﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Web;
using System.Diagnostics;
using System.Windows.Forms;
using System.Xml;
using System.Xml.Serialization;
using System.IO;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Net;
using System.Reflection;

using Microsoft.Win32;
using Codeplex.Data;
using UploadersLib.Helpers;

namespace NotYetTweetRead
{
    public partial class MainForm : Form
    {
        private TwitterSaveData g_Twitter = new TwitterSaveData();
        private oAuthTwitter g_oAuthTwitter = new oAuthTwitter("nrQFJUxDGLi3GgUHbUmByw", "HrgEUawiiPKXhejp5V32zUEjQdm7bawGrQehpPkw");
        Dictionary<string, TwitterUserData> TwitterListViewDictionary = new Dictionary<string, TwitterUserData>();
        private bool g_bUpDown = false;
        const int s_iTweetCount = 200;  //ツイートの1回の取得回数(max:200)

        //--------------------------------------------------------------------------
        //コンストラクタ
        //--------------------------------------------------------------------------
        public MainForm()
        {
            InitializeComponent();
        }
        //--------------------------------------------------------------------------
        //起動
        //--------------------------------------------------------------------------
        private void Form1_Load(object sender, EventArgs e)
        {

            //セーブロードの作り直しから

            //ダブルバッファ 
            System.Type myType = typeof(ListView);
            System.Reflection.PropertyInfo myPropertyInfo = myType.GetProperty("DoubleBuffered", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
            myPropertyInfo.SetValue(listView1, true, null);
            //バックグラウンド
            backgroundWorker1.DoWork += new DoWorkEventHandler(BackgroundWorker1_DoWork);
            backgroundWorker1.ProgressChanged += new ProgressChangedEventHandler(BackgroundWorker1_ProgressChanged);
            backgroundWorker1.RunWorkerCompleted += new RunWorkerCompletedEventHandler(BackgroundWorker1_RunWorkerCompleted);
            //設定をロード
            string ExeName = Assembly.GetExecutingAssembly().GetName().Name;
            string FileFolder = Path.Combine(System.Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), ExeName);
            string XMLFileName = Path.Combine(FileFolder, ExeName + ".xml");
            bool bLoad = false;
            if (File.Exists(XMLFileName) == true)
            {
                XmlSerializer serializer = new XmlSerializer(typeof(TwitterSaveData));
                System.IO.FileStream fs = new System.IO.FileStream(Path.Combine(FileFolder, ExeName + ".xml"), System.IO.FileMode.Open);
                g_Twitter = (TwitterSaveData)serializer.Deserialize(fs);
                if (CheckVersion(Assembly.GetExecutingAssembly().GetName().Version.ToString(), g_Twitter.Version) == true)
                {
                    List<TwitterUserData> ltlv = new List<TwitterUserData>();
                    g_oAuthTwitter.AuthInfo.Token = g_Twitter.AccessToken;
                    g_oAuthTwitter.AuthInfo.TokenSecret = g_Twitter.AccessTokenSecret;

                    foreach (TwitterUserSaveData user in g_Twitter.UserData)
                    {
                        TwitterUserData tud = AddTreeViewUser(user.UserName, user.CallName, user.ScreenName, user.UserID, user.SinceID, user.UserType, user.TweetType, user.Checked);
                        ltlv.Add(tud);
                    }
                    treeView1.ExpandAll();
                    int w = g_Twitter.TreeViewWidth;
                    g_bUpDown = g_Twitter.UpDown;
                    if (w > 0)
                    {
                        treeView1.Width = w;
                    }
                    //todo:セーフティネットとして必須項目がなかった場合は足す処理も入れよう
                    UpdateCheckBox.Checked = g_Twitter.UpdateCheck;
                    AutoUpdateCheckBox.Checked = g_Twitter.AutoUpdate;
                    TweetUpDownButton.Text = (!g_bUpDown) ? "▲" : "▼";
                    StartAllTimeLineThread(ltlv, false, true, 20);
                    bLoad = true;
                }
            }
            //ロードされていないのでログイン！
            if (bLoad == false)
            {
                LockLayout(false);
                LoginForm();
            }
        }
        //--------------------------------------------------------------------------
        //比較
        //--------------------------------------------------------------------------
        bool CheckVersion(string nowVersion, string fileVersion)
        {
            //起動時や0.3まではこのファイルはなかった
            if (fileVersion == null) return false;

            string[] nows = nowVersion.Split('.');
            string[] servers = fileVersion.Split('.');


            if (int.Parse(nows[0]) > int.Parse(servers[0]))
            {
                return true;
            }
            else
            {
                if (int.Parse(nows[1]) > int.Parse(servers[1]))
                {
                    return true;
                }
                else
                {
                    if (int.Parse(nows[2]) > int.Parse(servers[2]))
                    {
                        return true;
                    }
                }
            }
            return true;
        }
        //--------------------------------------------------------------------------
        //終了
        //--------------------------------------------------------------------------
        private void Form1_FormClosed(object sender, FormClosedEventArgs e)
        {
            if (backgroundWorker1.IsBusy == true)
            {
                backgroundWorker1.WorkerSupportsCancellation = true;
                backgroundWorker1.Dispose();
            }
            //セーブバッファ準備
            g_Twitter.UserData.Clear();
            List<TwitterUserSaveData> TwitterListViews = new List<TwitterUserSaveData>();
            foreach (TwitterUserData tlv in TwitterListViewDictionary.Values)
            {
                TwitterUserSaveData save = new TwitterUserSaveData();
                save.ScreenName = tlv.CallScreenName;
                save.UserName = tlv.UserName;
                save.CallName = tlv.CallName;
                save.UserID = tlv.UserID;
                //チェックしていない時は差分をセーブしない
                if (tlv.node.Checked == false)
                {
                    save.SinceID = 1;
                }
                else if (tlv.SelectID == 0)
                {
                    save.SinceID = tlv.NewID;
                }
                else
                {
                    save.SinceID = tlv.SelectID;
                }
                save.UserType = tlv.type;
                save.TweetType = tlv.TweetType;
                save.Checked = tlv.node.Checked;
                g_Twitter.UserData.Add(save);
            }
            if (g_oAuthTwitter.AuthInfo.Token != null)
            {
                g_Twitter.Version = Assembly.GetExecutingAssembly().GetName().Version.ToString();
                g_Twitter.AccessToken = g_oAuthTwitter.AuthInfo.Token;
                g_Twitter.AccessTokenSecret = g_oAuthTwitter.AuthInfo.TokenSecret;
                g_Twitter.TreeViewWidth = treeView1.Width;
                g_Twitter.UpDown = g_bUpDown;
                g_Twitter.UpdateCheck = UpdateCheckBox.Checked;
                g_Twitter.AutoUpdate = AutoUpdateCheckBox.Checked;
                //セーブファイル準備
                string ExeName = Assembly.GetExecutingAssembly().GetName().Name;
                string FileFolder = Path.Combine(System.Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), ExeName);
                if (Directory.Exists(FileFolder) == false)
                {
                    Directory.CreateDirectory(FileFolder);
                }
                //セーブ
                XmlSerializer TwitterSaveDataXML = new XmlSerializer(typeof(TwitterSaveData));
                using (StreamWriter write = new StreamWriter(Path.Combine(FileFolder, ExeName + ".xml"), false, Encoding.UTF8))
                {
                    TwitterSaveDataXML.Serialize(write, g_Twitter);
                    write.Close();
                }
                //終了時に自動アップデート
                if (UpdateCheckBox.Checked)
                {
#if DEBUG
#else
                string exePath = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
                Process.Start(Path.Combine(exePath,"CookieTweetUpdate.exe"));
#endif
                }
            }
        }
        //--------------------------------------------------------------------------
        //開始項目として必要最低限は強制追加
        //--------------------------------------------------------------------------
        public void AddTreeViewStart(List<TwitterUserData> ltlv)
        {
            AddTreeViewUser("home", "home", "ホーム", 0, 1, TwitterUserData.TYPE_HOME, TwitterUserData.TWEET_TYPE_NULL, true);
            AddTreeViewUser("home", "home_timeline", "タイムライン", 0, 1, TwitterUserData.TYPE_HOME, TwitterUserData.TWEET_TYPE_NORMAL, true);
            AddTreeViewUser("home", "mention", "@関連", 0, 1, TwitterUserData.TYPE_HOME, TwitterUserData.TWEET_TYPE_NORMAL, true);
            //AddTreeViewUser("home", "retweeted", "ﾘﾂｲｰﾄ", 0, 1, TwitterUserData.TYPE_HOME, TwitterUserData.TWEET_TYPE_NULL, true);
            AddTreeViewUser("home", "retweeted_to_me", "みんなのﾘﾂｲｰﾄ", 0, 1, TwitterUserData.TYPE_HOME, TwitterUserData.TWEET_TYPE_NORMAL, true);
            AddTreeViewUser("home", "retweeted_by_me", "あなたのﾘﾂｲｰﾄ", 0, 1, TwitterUserData.TYPE_HOME, TwitterUserData.TWEET_TYPE_NORMAL, true);
            AddTreeViewUser("home", "retweets_of_me", "ﾘﾂｲｰﾄされたあなたのﾂｲｰﾄ", 0, 1, TwitterUserData.TYPE_HOME, TwitterUserData.TWEET_TYPE_NORMAL, true);
            //AddTreeViewUser("home", "search", "検索メモ", 0, 1, TwitterUserData.TYPE_HOME, TwitterUserData.TWEET_TYPE_NULL, true);

            AddTreeViewUser(g_Twitter.UserName, "profile", "", 0, 1, TwitterUserData.TYPE_PROFILE, TwitterUserData.TWEET_TYPE_NULL, true);
            AddTreeViewUser(g_Twitter.UserName, "user_timeline", "ツイート", 0, 1, TwitterUserData.TYPE_PROFILE, TwitterUserData.TWEET_TYPE_NORMAL, true);
            AddTreeViewUser(g_Twitter.UserName, "favorites", "お気に入り", 0, 1, TwitterUserData.TYPE_PROFILE, TwitterUserData.TWEET_TYPE_NORMAL, true);
            //フォローはフォーマットが違う
            //AddTreeViewUser(g_Twitter.UserName, "friends", "フォローしている", 0, 1, TwitterUserData.TYPE_PROFILE, TwitterUserData.TWEET_TYPE_FOLLOW, true);
            //AddTreeViewUser(g_Twitter.UserName, "followers", "フォローされている", 0, 1, TwitterUserData.TYPE_PROFILE, TwitterUserData.TWEET_TYPE_FOLLOW, true);
            //ツイート登録
            treeView1.ExpandAll();
            foreach (TwitterUserData tud in TwitterListViewDictionary.Values)
            {
                if (tud.TweetType != TwitterUserData.TWEET_TYPE_NULL)
                {
                    ltlv.Add(tud);
                }
            }
#if false
                //リストはよく分からない
            AddTreeViewUser("listslists", "リスト", 0, 1, TwitterUserData.TYPE_LIST);
                url = "http://api.twitter.com/1/lists.xml";
                                xml = g_oAuthTwitter.oAuthWebRequest(oAuthTwitter.Method.GET, url, "screen_name=" + g_Twitter.UserName);
                                xdoc = new XmlDocument();
                                xdoc.LoadXml(xml);
                                mylist = xdoc.GetElementsByTagName("lists_list");
                                for (int i = 0; i < mylist.Count; i++)
                                {
                                    string tweet = mylist[i].ChildNodes[2].InnerText;
                                    TreeNode n = searchTud.node.Nodes.Add(tweet);
                                    n.Tag = tweet;
                                    n.ImageIndex = 0;
                                    n.SelectedImageIndex = 0;
                                    TwitterUserData tud = new TwitterUserData();
                                    tud.UserName = tweet;
                                    tud.ScreenName = tweet;
                                    tud.NewID = 1;
                                    tud.type = TwitterUserData.TYPE_SEARCH_WORD;
                                    tud.node = n;
                                    TwitterListViewDictionary[tweet] = tud;
                                }
#endif
        }
        //--------------------------------------------------------------------------
        //ツリービューへのユーザー追加
        //--------------------------------------------------------------------------
        private TwitterUserData AddTreeViewUser(string userName, string callName, string callScreenName, ulong userID, ulong newID, int type, int tweetType, bool check)
        {
            string screenName = "";
            //プロフィール
            if (callName == "profile")
            {
                string url = "https://api.twitter.com/1/users/show.json/";
                string post = "screen_name=" + userName;
                string json = g_oAuthTwitter.oAuthWebRequest(oAuthTwitter.Method.GET, url, post);
                var statuses = DynamicJson.Parse(json);

                callScreenName = statuses.name;
                screenName = statuses.name;
                userID = (ulong)statuses.id;
                Bitmap bmp = GetProfileImage(statuses.profile_image_url);
                userMiniImageList.Images.Add(bmp);
            }
            else if (type == TwitterUserData.TYPE_HOME)
            {
                screenName = "ホーム";
            }
            else
            {
                TwitterUserData profileName = TwitterListViewDictionary[userName + "profile"];
                screenName = profileName.ScreenName;
            }

            //ノードチェック
            TreeNode node = null;
            if (type == TwitterUserData.TYPE_HOME)
            {
                if (callName == "home")
                {
                    node = treeView1.Nodes.Add(callScreenName);
                }
                else
                {
                    TwitterUserData homeTud = TwitterListViewDictionary[userName + "home"];

                    if (callName == "home_timeline" || callName == "mention")
                    {
                        node = homeTud.node.Nodes.Add(callScreenName + "(0)");
                    }
                    else if (callName == "retweeted" || callName == "search")
                    {
                        node = homeTud.node.Nodes.Add(callScreenName);
                    }
                    else if (callName == "retweeted_to_me" || callName == "retweeted_by_me" || callName == "retweets_of_me")
                    {
                        //TwitterUserData retweetedTud = TwitterListViewDictionary[userName + "retweeted"];
                        node = homeTud.node.Nodes.Add(callScreenName + "(0)");
                    }
                    else if (callName == "saved_search")
                    {
                        TwitterUserData searchTud = TwitterListViewDictionary[userName + "search"];
                        node = searchTud.node.Nodes.Add(callScreenName + "(0)");
                    }
                }
            }
            else if (type == TwitterUserData.TYPE_PROFILE)
            {
                if (callName == "profile")
                {
                    node = treeView1.Nodes.Add(callScreenName);
                }
                else
                {
                    TwitterUserData profileTud = TwitterListViewDictionary[userName + "profile"];
                    if (callName == "user_timeline" || callName == "favorites" || callName == "friends" || callName == "followers")
                    {
                        node = profileTud.node.Nodes.Add(callScreenName + "(0)");
                    }
                    else
                    {
                        node = profileTud.node.Nodes.Add(callScreenName);
                    }
                }
            }
            node.ImageIndex = 0;
            node.SelectedImageIndex = 0;
            node.Checked = check;
            TwitterUserData tlv = new TwitterUserData();
            tlv.UserName = userName;
            tlv.ScreenName = screenName;
            tlv.CallName = callName;
            tlv.CallScreenName = callScreenName;
            tlv.UserID = userID;
            tlv.NewID = newID;
            tlv.type = type;
            tlv.TweetType = tweetType;
            tlv.node = node;

            //この名前は絶対にユニークに
            node.Tag = userName + callName;
            TwitterListViewDictionary[userName + callName] = tlv;

            //この処理はTwitterListViewDictionaryを入れてから
            //検索メモ
            if (callName == "search")
            {
                string url = "http://api.twitter.com/1/saved_searches.json";
                string json = g_oAuthTwitter.oAuthWebRequest(oAuthTwitter.Method.GET, url, "");
                var statuses = DynamicJson.Parse(json);
                foreach (var status in (dynamic[])statuses)
                {
                    AddTreeViewUser(userName, "saved_search", status.name, 0, 1, TwitterUserData.TYPE_HOME, TwitterUserData.TWEET_TYPE_SEARCH, false);
                }
            }
            if (type == TwitterUserData.TYPE_PROFILE)
            {
                TwitterUserData profileTud = TwitterListViewDictionary[userName + "profile"];
                tlv.UserID = profileTud.UserID;
                tlv.Icon = (Bitmap)userMiniImageList.Images[userMiniImageList.Images.Count - 1];
                tlv.node.ImageIndex = userMiniImageList.Images.Count - 1;
                tlv.node.SelectedImageIndex = userMiniImageList.Images.Count - 1;
            }
            return tlv;
        }
        //--------------------------------------------------------------------------
        //ログインフォーム
        //--------------------------------------------------------------------------
        private void LoginForm()
        {
            LoginForm form = new LoginForm(g_Twitter, g_oAuthTwitter);
            DialogResult result = form.ShowDialog();
            if (result == DialogResult.OK)
            {
                //全部消す
                treeView1.Nodes.Clear();
                listView1.Items.Clear();
                TwitterListViewDictionary.Clear();
                //ホームを登録
                List<TwitterUserData> ltlv = new List<TwitterUserData>();
                AddTreeViewStart(ltlv);
                //treeView1.SelectedNode = treeView1.TopNode;
                StartAllTimeLineThread(ltlv, false, true, 20);
            }
        }
        //--------------------------------------------------------------------------
        //バブルソート
        //--------------------------------------------------------------------------
        private void TwitterListViewBubbleSort(TwitterUserData tlv)
        {
            int n = tlv.tlvi.Count;
            for (int i = 0; i < n - 1; i++)
            {
                for (int j = n - 1; j > i; j--)
                {
//                    if (tlv.tlvi[j].TweetTime > tlv.tlvi[j - 1].TweetTime)
                    if (tlv.tlvi[j].TweetId > tlv.tlvi[j - 1].TweetId)
                    {
                        TwitterTweetData tlvi = tlv.tlvi[j];
                        tlv.tlvi[j] = tlv.tlvi[j - 1];
                        tlv.tlvi[j - 1] = tlvi;
                    }
                }
            }
        }
        //--------------------------------------------------------------------------
        //レイアウトのロック
        //--------------------------------------------------------------------------
        private void LockLayout(bool bLock)
        {
            //TweetButton.Enabled = bLock;
            ListViewContextMenuStrip.Enabled = bLock;
            TreeViewcontextMenuStrip.Enabled = bLock;
            TweetUpDownButton.Enabled = bLock;
        }
        //--------------------------------------------------------------------------
        //全てのタイムラインを取得開始
        //--------------------------------------------------------------------------
        List<TwitterThreadData> g_TwitterThreadListView = new List<TwitterThreadData>();
        int g_iTwitterThredListIndex = 0;
        int g_iTwitterThredAllMax = 0;
        int g_iTwitterThredOneMax = 0;
        int g_iTwitterThredCo = 0;
        private void StartAllTimeLineThread(List<TwitterUserData> tlv, bool bTimer, bool bNew, int tweetNum)
        {
            if (backgroundWorker1.IsBusy) return;
            //レイアウトのロック
            toolStripStatusLabel1.Text = tlv[0].ScreenName + "の" + tlv[0].CallScreenName + "確認中";
            backgroundWorker1.WorkerReportsProgress = true;
            toolStripStatusLabel2.Text = "";
            toolStripStatusLabel3.Text = "";
            toolStripStatusLabel3.Visible = true;
            toolStripStatusLabel3.Image = (tlv[0].Icon != null) ? tlv[0].Icon : userMiniImageList.Images[0];
            timer1.Enabled = false;

            LockLayout(false);
            //初期化
            g_iTwitterThredAllMax = 0;
            g_iTwitterThredListIndex = 0;
            g_TwitterThreadListView.Clear();
            foreach (TwitterUserData tv in tlv)
            {
                TwitterThreadData ttlv = new TwitterThreadData();
                ttlv.g_tlv = tv;
                ttlv.g_bTimer = bTimer;
                ttlv.g_bNew = bNew;
                ttlv.g_tweetNum = tweetNum;
                g_TwitterThreadListView.Add(ttlv);
            }
            backgroundWorker1.RunWorkerAsync();
        }
        //--------------------------------------------------------------------------
        //タイムラインの取得終了処理
        //--------------------------------------------------------------------------
        private void BackgroundWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            if (backgroundWorker1.WorkerSupportsCancellation) return;

            toolStripProgressBar1.Visible = false;
            toolStripStatusLabel2.Visible = false;
            toolStripStatusLabel3.Visible = false;
            toolStripStatusLabel1.Text = "";
            treeView1.Enabled = true;
            TweetButton.Enabled = true;
            if (treeView1.SelectedNode == null)
            {
                TwitterUserData homeTud = TwitterListViewDictionary["homehome_timeline"];
                treeView1.SelectedNode = homeTud.node;
            }
            else
            {
                //自動更新スタート
                if (treeView1.SelectedNode.Checked == true && AutoUpdateCheckBox.Checked == true)
                {
                    timer1.Enabled = true;
                    if (treeView1.SelectedNode == null)
                    {
                        timer1.Enabled = false;
                    }
                    else
                    {
                        TwitterUserData tlv = TwitterListViewDictionary[treeView1.SelectedNode.Tag.ToString()];
                        if (tlv.CallName == "profile" || tlv.CallName == "home")
                        {
                            timer1.Enabled = false;
                        }
                    }
                }
                LockLayout(true);
                listView1.Focus();
                iTimer = 0;
            }
        }
        //--------------------------------------------------------------------------
        //タイムラインの取得処理
        //--------------------------------------------------------------------------
        string g_Format = "xml";
        private void BackgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
        {
            BackgroundWorker bgWorker = (BackgroundWorker)sender;
            foreach (TwitterThreadData ttlv in g_TwitterThreadListView)
            {
                TwitterUserData tlv = ttlv.g_tlv;
                int TweetMax = 0;
                int TweetCount = 0;
                int page = 1;
                string url = "";


                if (tlv.CallName == "home_timeline")
                {
                    url = "http://api.twitter.com/1/statuses/home_timeline." + g_Format;
                    TweetMax = 800;
                    TweetCount = 200;
                }
                else if (tlv.CallName == "mention")
                {
                    url = "http://api.twitter.com/1/statuses/mentions." + g_Format;
                    TweetMax = 800;
                    TweetCount = 200;
                }
                else if (tlv.CallName == "retweeted_to_me")
                {
                    url = "http://api.twitter.com/1/statuses/retweeted_to_me." + g_Format;
                    TweetMax = 800 * 2;
                    TweetCount = 100;
                }
                else if (tlv.CallName == "retweeted_by_me")
                {
                    url = "http://api.twitter.com/1/statuses/retweeted_by_me." + g_Format;
                    TweetMax = 800 * 2;
                    TweetCount = 100;
                }
                else if (tlv.CallName == "retweets_of_me")
                {
                    url = "http://api.twitter.com/1/statuses/retweets_of_me." + g_Format;
                    TweetMax = 800 * 2;
                    TweetCount = 100;
                }
                else if (tlv.CallName == "saved_search")
                {
                    url = "http://search.twitter.com/search." + g_Format;
                    //url = "http://search.twitter.com/search." + "atom";
                    TweetMax = 1500;
                    TweetCount = 200;
                }
                else if (tlv.CallName == "user_timeline")
                {
                    url = "http://api.twitter.com/1/statuses/user_timeline/" + tlv.UserID + "." + g_Format;
                    TweetMax = 3200;
                    TweetCount = 200;
                }
                else if (tlv.CallName == "favorites")
                {
                    url = "http://api.twitter.com/1/favorites." + g_Format;
                    TweetMax = 3200;
                    TweetCount = 200;
                }
                else if (tlv.CallName == "friends")
                {
                    url = "http://api.twitter.com/1/statuses/friends." + g_Format;
                    TweetMax = 800;
                    TweetCount = 200;
                }
                else if (tlv.CallName == "followers")
                {
                    url = "http://api.twitter.com/1/statuses/followers." + g_Format;
                    TweetMax = 800;
                    TweetCount = 200;
                }
                //特殊処理
                else if (tlv.CallName == "update")
                {
                    System.Threading.Thread.Sleep(2000);
                    g_iTwitterThredListIndex++;
                    continue;
                }


                bool bTimer = ttlv.g_bTimer;
                bool bNew = ttlv.g_bNew;
                int tweetNum = ttlv.g_tweetNum;
                int iErrorCo = 0,iErrorPage=0;
                int iInsertCo = 0;
                
                for (page = 1; page <= TweetMax / s_iTweetCount; page++)
                {

                    bool bLoopEnd = false;
                    string encmes = "";
                    oAuthTwitter.Method method = oAuthTwitter.Method.GET;

                    if (tlv.TweetType == TwitterUserData.TWEET_TYPE_SEARCH)
                    {
                        encmes = string.Format("q={0:s}&rpp=100&page=" + page, System.Web.HttpUtility.UrlEncode(tlv.UserName));
                        if (bNew == false)
                        {
                            encmes += "&max_id=" + tlv.OldID;
                        }
                    }
                    else if (tlv.TweetType == TwitterUserData.TWEET_TYPE_NORMAL)
                    {
                        encmes = string.Format("include_entities=true&include_rts=true&count=" + TweetCount + "&page=" + page);
                        if (bNew == false)
                        {
                            encmes += "&max_id=" + tlv.OldID;
                        }
                        if (tlv.CallName == "favorites")
                        {
                            encmes += "&id=" + tlv.UserID;
                        }
                    }

                    string xml = g_oAuthTwitter.oAuthWebRequest(method, url, encmes);
                    //Twitter側のエラー
                    if (xml.Substring(0, "<?xml ".Length) != "<?xml ")
                    {
                        if (page == iErrorPage)
                        {
                            iErrorCo++;
                        }
                        else
                        {
                            iErrorCo = 0;
                        }
                        //同じのが2回続けば処理終了
                        if (iErrorCo > 2)
                        {
                            break;
                        }
                        iErrorPage = page;
                        page--;
                        continue;
                    }
                    //XML解析
                    XmlDocument xdoc = new XmlDocument();
                    try
                    {
                        xdoc.LoadXml(xml);
                    }
                    catch (XmlException)
                    {
                        page--;
                        continue;
                    }
                    XmlElement root = xdoc.DocumentElement;
                    XmlNodeList mylist = null;

                    if (tlv.TweetType == TwitterUserData.TWEET_TYPE_SEARCH)
                    {
                        mylist = root.GetElementsByTagName("entry");
                    }
                    else
                    {
                        mylist = root.GetElementsByTagName("status");
                    }
                    //最大値を数えておく
                    g_iTwitterThredCo = 0;
                    g_iTwitterThredOneMax = mylist.Count;
                    for (int i = 0; i < mylist.Count; i++)
                    {
                        ulong iTweetID;
                        if (tlv.TweetType == TwitterUserData.TWEET_TYPE_SEARCH)
                        {
                            string id = mylist[i].ChildNodes[0].InnerText.Substring(mylist[i].ChildNodes[0].InnerText.LastIndexOf(":") + 1);
                            iTweetID = ulong.Parse(id);
                        }
                        else
                        {
                            iTweetID = ulong.Parse(mylist[i].ChildNodes[1].InnerText);
                        }

                        //再更新のカウントまで
                        if (bNew == false && i + iInsertCo >= tweetNum - 1)
                        {
                            //再更新の初回は既存のIDなので無視
                            g_iTwitterThredOneMax = i;
                            bLoopEnd = true;
                            break;
                        }
                        //登録時はカウントまで
                        if (bNew == true && i + iInsertCo >= tweetNum - 1 && tlv.NewID <= 1)
                        {
                            g_iTwitterThredOneMax = i + 1;
                            bLoopEnd = true;
                            break;
                        }
                        //登録でタイマーの時はNewIDが前回が同じならなし
                        if (bNew == true && bTimer == true && iTweetID <= tlv.NewID && tlv.NewID > 1)
                        {
                            g_iTwitterThredOneMax = i;
                            bLoopEnd = true;
                            break;
                        }
                        //登録時はNewIDが前回が同じまで
                        if (bNew == true && iTweetID <= tlv.NewID && tlv.NewID > 1)
                        {
                            g_iTwitterThredOneMax = i + 1;
                            bLoopEnd = true;
                            break;
                        }
                    }
                    g_iTwitterThredAllMax += g_iTwitterThredOneMax;
                    bgWorker.ReportProgress(-1);

                    //マルチコアは先にnewしておく
                    //こんなnewで良いのか？
                    TwitterTweetData[] tlvi = new TwitterTweetData[g_iTwitterThredOneMax];
                    for (int i = 0; i < g_iTwitterThredOneMax; i++)
                    {
                        tlvi[i] = new TwitterTweetData();
                    }
                    Regex reg = new Regex("^([A-Z][a-z][a-z]) ([A-Z][a-z][a-z]) ([0-9]{1,2}) ([0-9]{1,2}:[0-9][0-9]:[0-9][0-9]) (\\+[0-9]{4}) ([0-9]{4})$");
                    //マルチコア化
                    Parallel.For(0, g_iTwitterThredOneMax, (i) =>
                    {
                        try
                        {
                            if (tlv.TweetType == TwitterUserData.TWEET_TYPE_SEARCH)
                            {
                                string id = mylist[i].ChildNodes[0].InnerText.Substring(mylist[i].ChildNodes[0].InnerText.LastIndexOf(":") + 1);
                                tlvi[i].TweetId = ulong.Parse(id);

                                string stricon = mylist[i].ChildNodes[6].OuterXml.Substring(mylist[i].ChildNodes[6].OuterXml.IndexOf("href=\"") + "href=\"".Length);
                                stricon = stricon.Substring(0, stricon.IndexOf(" ") - 1);

                                Bitmap bmp = GetProfileImage(stricon);


                                tlvi[i].Tweet = mylist[i].ChildNodes[3].InnerText;
                                tlvi[i].Source = mylist[i].ChildNodes[9].ChildNodes[0].InnerText;

                                tlvi[i].UserName = mylist[i].ChildNodes[11].ChildNodes[0].InnerText.Substring(0, mylist[i].ChildNodes[11].ChildNodes[0].InnerText.IndexOf('(') - 1);
                                tlvi[i].ScreenName = mylist[i].ChildNodes[11].ChildNodes[0].InnerText.Substring(mylist[i].ChildNodes[11].ChildNodes[0].InnerText.IndexOf('(') + 1);
                                tlvi[i].ScreenName = tlvi[i].ScreenName.Substring(0, tlvi[i].ScreenName.Length - 1);

                                DateTime dt = DateTime.Parse(mylist[i].ChildNodes[1].InnerText);
                                tlvi[i].TweetTime = dt;

                                tlvi[i].Icon = bmp;
                                tlv.tlvi.Add(tlvi[i]);
                            }
                            else
                            {
                                ulong iTweetID = ulong.Parse(mylist[i].ChildNodes[1].InnerText);
                                //この処理が意外と重い
                                Bitmap bmp;
                                if (mylist[i].ChildNodes[11].ChildNodes[5].InnerText == "false")
                                {
                                    bmp = GetProfileImage(mylist[i].ChildNodes[11].ChildNodes[11].ChildNodes[5].InnerText);
                                }
                                else
                                {
                                    bmp = GetProfileImage(mylist[i].ChildNodes[11].ChildNodes[5].InnerText);
                                }
                                if (bmp == null)
                                {
                                    bmp = GetProfileImage(mylist[i].ChildNodes[11].ChildNodes[11].ChildNodes[5].InnerText);

                                }
                                string strReplace = reg.Replace(mylist[i].ChildNodes[0].InnerText, "$2 $3 $6 $4");
                                DateTime dt = DateTime.Parse(strReplace);
                                TimeSpan utcOffset = System.TimeZone.CurrentTimeZone.GetUtcOffset(dt);
                                dt += utcOffset;
                                tlvi[i].TweetTime = dt;
                                tlvi[i].TweetId = iTweetID;
                                //リツイート
                                if (mylist[i].ChildNodes[12].ChildNodes[0] != null && mylist[i].ChildNodes[12].ChildNodes[1] != null)
                                {
                                    tlvi[i].Tweet = mylist[i].ChildNodes[11].ChildNodes[2].InnerText + " ";
                                    tlvi[i].ReTweet = " ⇔ " + mylist[i].ChildNodes[12].ChildNodes[2].InnerText + "がリツイート";
                                    tlvi[i].UserName = mylist[i].ChildNodes[11].ChildNodes[11].ChildNodes[2].InnerText;
                                    tlvi[i].ScreenName = mylist[i].ChildNodes[11].ChildNodes[11].ChildNodes[1].InnerText;
                                    tlvi[i].UserID = ulong.Parse(mylist[i].ChildNodes[11].ChildNodes[11].ChildNodes[0].InnerText);
                                    tlvi[i].IconURL = mylist[i].ChildNodes[11].ChildNodes[11].ChildNodes[5].InnerText;
                                }
                                else
                                {
                                    tlvi[i].Tweet = mylist[i].ChildNodes[2].InnerText + " ";
                                    tlvi[i].ReTweet = "";
                                    tlvi[i].UserName = mylist[i].ChildNodes[11].ChildNodes[2].InnerText;
                                    tlvi[i].ScreenName = mylist[i].ChildNodes[11].ChildNodes[1].InnerText;
                                    tlvi[i].UserID = ulong.Parse(mylist[i].ChildNodes[11].ChildNodes[0].InnerText);
                                    tlvi[i].IconURL = mylist[i].ChildNodes[11].ChildNodes[5].InnerText;
                                }
                                tlvi[i].Favorited = bool.Parse(mylist[i].ChildNodes[5].InnerText);
                                tlvi[i].ReTweeted = bool.Parse(mylist[i].ChildNodes[10].InnerText);
                                tlvi[i].Source = mylist[i].ChildNodes[3].InnerText;
                                tlvi[i].Icon = bmp;
                                tlv.tlvi.Add(tlvi[i]);
                            }
                            iInsertCo++;
                            g_iTwitterThredCo++;
                            bgWorker.ReportProgress(-2);
                        }
                        catch (NullReferenceException)
                        {
                        }
                    });
                    //チェック
                    if (bLoopEnd)
                    {
                        break;
                    }
                }
                bgWorker.ReportProgress(iInsertCo);
            }
        }
        //--------------------------------------------------------------------------
        //タイムラインの取得UI処理
        //--------------------------------------------------------------------------
        private void BackgroundWorker1_ProgressChanged(object sender, ProgressChangedEventArgs e)
        {
            if (backgroundWorker1.WorkerSupportsCancellation) return;

            TwitterUserData tlv = g_TwitterThreadListView[g_iTwitterThredListIndex].g_tlv;
            bool bTimer = g_TwitterThreadListView[g_iTwitterThredListIndex].g_bTimer;
            //開始処理
            if (e.ProgressPercentage == -1)
            {
                if(g_iTwitterThredOneMax > 0)
                {

                    string tweetName = g_TwitterThreadListView[g_iTwitterThredListIndex].g_tlv.ScreenName + "の" + g_TwitterThreadListView[g_iTwitterThredListIndex].g_tlv.CallScreenName;
                    toolStripStatusLabel1.Text = tweetName + "取得中";

                    toolStripProgressBar1.Visible = true;
                    toolStripStatusLabel2.Visible = true;
                    toolStripProgressBar1.Maximum = g_iTwitterThredOneMax;
                }
            }
            //定刻処理
            else if (e.ProgressPercentage == -2)
            {
                if (g_iTwitterThredOneMax <= g_iTwitterThredCo)
                {
                    string tweetName = g_TwitterThreadListView[g_iTwitterThredListIndex].g_tlv.ScreenName + "の" + g_TwitterThreadListView[g_iTwitterThredListIndex].g_tlv.CallScreenName;
                    toolStripStatusLabel1.Text = tweetName + "確認中(" + g_iTwitterThredAllMax + "個取得済)";
                    toolStripProgressBar1.Value = 0;
                    toolStripProgressBar1.Visible = false;
                    toolStripStatusLabel2.Visible = false;
                }
                else if (g_iTwitterThredOneMax > 0)
                {
                    toolStripStatusLabel2.Text = (g_iTwitterThredAllMax - g_iTwitterThredOneMax + g_iTwitterThredCo) + "/" + g_iTwitterThredAllMax + "個";
                    toolStripProgressBar1.Value = g_iTwitterThredCo;
                }
            }
            //アイコン処理
            else if (e.ProgressPercentage == -3)
            {
                userMiniImageList.Images.Add(tlv.Icon);
                tlv.IconIndex = userMiniImageList.Images.Count - 1;
                tlv.node.ImageIndex = tlv.IconIndex;
                tlv.node.SelectedImageIndex = tlv.IconIndex;
                toolStripStatusLabel3.Image = tlv.Icon;
            }
            //終了処理
            else
            {
                toolStripProgressBar1.Visible = false;
                toolStripStatusLabel2.Visible = false;
                g_iTwitterThredAllMax = 0;
                //次の情報に進める
                g_iTwitterThredListIndex++;
                if (g_TwitterThreadListView.Count > g_iTwitterThredListIndex)
                {
                    string tweetName = g_TwitterThreadListView[g_iTwitterThredListIndex].g_tlv.ScreenName + "の" + g_TwitterThreadListView[g_iTwitterThredListIndex].g_tlv.CallScreenName;
                    toolStripStatusLabel1.Text = tweetName + "確認中";
                    toolStripStatusLabel3.Image = g_TwitterThreadListView[g_iTwitterThredListIndex].g_tlv.Icon;
                }
                if (e.ProgressPercentage == 0) return;

                //ツリービューに追加
                tlv.NotReadNum += e.ProgressPercentage;
                if (tlv.NotReadNum == 0)
                {
                    tlv.node.NodeFont = new Font(this.Font, FontStyle.Regular);
                }
                else
                {
                    tlv.node.NodeFont = new Font(this.Font, FontStyle.Bold);
                }
                //ソートして選択を設定
                TwitterListViewBubbleSort(tlv);
                if (g_bUpDown == false)
                {
                    if (bTimer == true)
                    {
                        if (tlv.SelectIndex >= 0)
                        {
                            tlv.SelectIndex += e.ProgressPercentage;
                        }
                    }
                    else
                    {
                        tlv.SelectIndex += e.ProgressPercentage - 1;
                    }
                    tlv.SelectID = tlv.tlvi[tlv.SelectIndex].TweetId;
                }
                else
                {
                    tlv.SelectID = tlv.tlvi[tlv.tlvi.Count - 1 - tlv.SelectIndex].TweetId;
                }
                tlv.NewID = tlv.tlvi[0].TweetId;
                tlv.OldID = tlv.tlvi[tlv.tlvi.Count - 1].TweetId;

                tlv.node.Text = tlv.CallScreenName + "(" + tlv.NotReadNum + ")";
                //選択中のリストビューに追加
                if (treeView1.SelectedNode != null && tlv.UserName + tlv.CallName == treeView1.SelectedNode.Tag.ToString())
                {
                    for (int i = 0; i < e.ProgressPercentage; i++)
                    {
                        int idx;
                        if (g_bUpDown == false)
                        {
                            idx = i;
                        }
                        else
                        {
                            idx = (listView1.Items.Count > 0) ? (listView1.Items.Count - 1) - (i - 1) : 0;
                        }
                        TwitterTweetData tlvi = tlv.tlvi[i];
                        ListViewItem lvi = listView1.Items.Insert(idx, tlvi.Tweet);
                        homeImageList.Images.Add(tlvi.Icon);
                        lvi.ImageIndex = homeImageList.Images.Count - 1;
                        AddTweet(lvi, tlvi);
                    }
                    listViewFont(true);
                }
            }
        }
        //--------------------------------------------------------------------------
        //ツイート追加
        //--------------------------------------------------------------------------
        private void AddTweet(ListViewItem lvi, TwitterTweetData tlvi)
        {
            string source = Regex.Replace(tlvi.Source, @"<.*?>", string.Empty) + "から";
            lvi.SubItems.Add(tlvi.TweetTime.ToString("F"));
            lvi.SubItems.Add(source);
            lvi.Font = new Font(this.Font, FontStyle.Bold);
        }
        //--------------------------------------------------------------------------
        //コメントの中のURLなどをリンクに置き換える
        //--------------------------------------------------------------------------
        private string ReplaceLink(string Comment)
        {
            //リンク
            Comment =  System.Text.RegularExpressions.Regex.Replace(
                Comment,
                @"s?https?://[-_.!~*'()a-zA-Z0-9;/?:@&=+$,%#]+",
                "<a href=\"$&\" target=\"_blank\">$&</a>");
            //@a-zと_が入った20文字以内の名前
            Comment = System.Text.RegularExpressions.Regex.Replace(
                Comment,
                @"@[a-z\d_]{1,20}",
                "<a href=\"http://twitter.com/$& \" target=\"_blank\">$&</a>",
                RegexOptions.IgnoreCase
                );

            //#ハッシュタグ
            Comment = System.Text.RegularExpressions.Regex.Replace(
               Comment,
               @"(#.*?( |#|？|\?|。|\.|:))",
               "<a href=\"http://twitter.com/#!/search?q=%23$&\" target=\"_blank\">$&</a>"
               );
            //#を抜く
            Comment = Comment.Replace(
               "<a href=\"http://twitter.com/#!/search?q=%23#",
               "<a href=\"http://twitter.com/#!/search?q=%23"
               );
            return Comment;
        }
        //--------------------------------------------------------------------------
        //セットトップツイート
        //--------------------------------------------------------------------------
        private void SetTopTweet(string Comment, string NameEN, string NameJP, DateTime Time, string IconURL)
        {
            string strHtml = "";
            if (NameEN == "")
            {
                strHtml = "";
            }
            else
            {
                double sec = (DateTime.Now - Time).TotalSeconds;
                string strTime = "";
                if (sec < 60)
                {
                    strTime = (int)sec + "秒前";
                }
                else if (sec < 60 * 60)
                {
                    strTime = (int)sec / 60 + "分前";
                }
                else if (sec < 60 * 60 * 24)
                {
                    strTime = (int)sec / 60 / 60 + "時間前";
                }
                else
                {
                    strTime = Time.Month + "月 " + Time.Day + "日";
                }
                strHtml = "<html>";
                strHtml += "<head>";
                strHtml += "<meta http-equiv='Content-type' content='text/html' charset='Shift_JIS'>";
                strHtml += "<title></title>";
                strHtml += "<link rel='stylesheet' href='https://si0.twimg.com/a/1309196069/phoenix/css/phoenix.bundle.css' type='text/css' media='screen' />";
                strHtml += "<style type='text/css' media='screen'>.stream{position:relative;background-color:#fff;padding-top:1px;min-height:800px;margin-top:1px;zoom:1;}.stream .stream-item:first-child,.stream .hovered-stream-item:first-child,.related-tweets .stream-item:first-child:hover{border-top:none;}.stream-item{position:relative;border-bottom:1px solid #ebebeb;min-height:60px;clear:both;display:block;outline:none;margin-top:-1px;border-top:1px solid transparent;}.stream-item.blocked{display:none;}.stream-item:hover,.related-tweets .stream-item:hover,.hovered-stream-item{cursor:pointer;background:#f4f4f4;border-top:1px solid #EBEBEB;}.stream-item[data-item-type='list']{border-color:#EBEBEB!important;background:#fff!important;}.stream-item .more{_visibility:hidden!important;display:none;width:17px;height:18px;background:red;position:absolute;margin-top:8px;z-index:1;outline:none;text-indent:-99999px;right:10px;background:url(http://a1.twimg.com/a/1312996508/phoenix/img/sprite-icons.png) no-repeat -288px 0;}.stream-item .more:hover{background:url(http://a1.twimg.com/a/1312996508/phoenix/img/sprite-icons.png) no-repeat -288px -32px;}.stream-item:active .more{background:url(http://a1.twimg.com/a/1312996508/phoenix/img/sprite-icons.png) no-repeat -288px -64px;}.stream-item:hover .more,.hovered-stream-item .more{display:block;}.stream-item.focused-stream-item .more{background:url(http://a1.twimg.com/a/1312996508/phoenix/img/sprite-icons.png) no-repeat -320px 0;}.stream-item.focused-stream-item .more:hover{background:url(http://a1.twimg.com/a/1312996508/phoenix/img/sprite-icons.png) no-repeat -320px -32px;}.stream-item.focused-stream-item:active .more{background:url(http://a1.twimg.com/a/1312996508/phoenix/img/sprite-icons.png) no-repeat -320px -64px;}.stream-item .arrow{display:none;width:17px;height:29px;background:red;position:absolute;margin-top:3px;z-index:6;outline:none;text-indent:-99999px;right:-17px;background:url(http://a1.twimg.com/a/1312996508/phoenix/img/pointer-right-hover.png);}.focused-stream-item,.focused-stream-item:hover{cursor:pointer;background:#eee;border-bottom:1px solid #ccc;margin-top:-1px;border-top:1px solid #ccc;outline:none;}.focused-stream-item:hover .arrow,.focused-stream-item .arrow{display:block!important;}.hovered-stream-item,.related-tweets .stream-item:hover{background:#f4f4f4;}.stream-loading{position:relative;height:60px;text-align:center;}.stream-loading .spinner{display:block;height:32px;width:32px;background-image:url(http://a1.twimg.com/a/1312996508/phoenix/img/loader.gif);margin:10px auto;}.stream-end,.stream-whale-end{position:relative;min-height:60px;text-align:center;color:#666;}.stream-end{padding:20px 15px;}.stream-whale-end{padding:20px 80px;}.stream-end img{margin:5px 3px -5px 0;}.stream-end div{margin-top:2px;}.stream-whale-end .title{font-weight:bold;}.stream-title h2{padding:14px 20px 5px 20px;font-size:15px;font-weight:300;margin-bottom:0;color:#666;}.stream-title .go-to-list-page{float:right;text-decoration:none;font-size:12px;font-weight:normal;}#new-tweets-bar{font-size:13px;display:block;padding:5px 1px;margin:10px 15px 10px 15px;cursor:pointer;background:#E3F1FA;border:1px solid #C6E4F2;text-align:center;text-shadow:0 1px 0 #fff;-moz-border-radius:3px;-webkit-border-radius:3px;border-radius:3px;z-index:2;}#new-tweets-bar:hover{background:#D9ECF9;border-color:#B1D4E4;}#new-tweets-bar:active{background:#E3F1FA;}.stream-list{padding:10px 20px;}.list-image{width:36px;height:36px;float:left;}.list-content{margin-left:51px;position:relative;}.list-name{display:block;}.list-description{display:block;}.list-buttons{position:absolute;top:0;right:0;}.pending-request{float:left;font-size:12px;margin:4px 3px 0;}.more-button{cursor:pointer;text-decoration:none;background:#fff url(http://a1.twimg.com/a/1312996508/phoenix/img/more.gif) repeat-x left top;border-color:#ddd #aaa #aaa #ddd;border-style:solid;border-width:1px;display:block;font-size:14px;font-weight:bold;height:22px;line-height:1.5em;margin:6px auto;outline:medium none;padding:6px 0;text-align:center;text-shadow:1px 1px 1px #fff;width:97%;border-radius:5px;-moz-border-radius:5px;-webkit-border-radius:5px;}.more-button:hover{background-position:left -78px;border:1px solid #bbb;text-decoration:none;}.query-token{font-weight:bold;}.stream-tabs,.stream-subtabs{padding:0 10px;border-bottom:1px solid #eee;list-style-type:none;display:block;clear:both;margin:0;}.stream-tabs{height:30px;}.stream-subtabs{display:none;height:35px;padding-top:7px;}.stream-subtabs.active{display:block;}body.ja .profile-header .stream-tabs,body.ja .profile-header .stream-tabs .tab-text,body.ja .profile-header .stream-tabs .stream-tab.active .tab-text{height:50px;}.stream-tabs .stream-tab,.stream-subtabs .stream-tab{padding:0;margin:0;float:left;position:relative;cursor:pointer;}.stream-tabs .stream-tab{-webkit-border-top-left-radius:4px;-webkit-border-top-right-radius:4px;-moz-border-radius-topleft:4px;-moz-border-radius-topright:4px;border-top-left-radius:4px;border-top-right-radius:4px;}.stream-tabs .stream-tab .drop-down{cursor:default;}.stream-tabs .tab-text,.stream-subtabs .tab-text{text-decoration:none;cursor:pointer;display:block;outline:none;line-height:24px;overflow:hidden;}.stream-tabs .tab-text{padding:4px 10px 3px;border-radius:inherit;-webkit-border-radius:inherit;-moz-border-radius:inherit;text-overflow:ellipsis-word;text-shadow:0 1px 0 #fff;}.stream-subtabs .tab-text{padding:1px 7px;}.stream-tabs .tab-text i{background-position:-47px -64px;width:7px;background-image:url(http://a1.twimg.com/a/1312996508/phoenix/img/sprite-icons.png);background-repeat:no-repeat;display:inline-block;opacity:.4;height:13px;outline:medium none;overflow:hidden;margin-left:4px;position:relative;top:2px;border:none;*left:4px;*top:0;_margin-top:8px;}.stream-tabs .stream-tab:hover .tab-text i{opacity:1;}.stream-tabs .stream-tab.active .tab-text,.stream-tabs .stream-tab.active .tab-text:hover{border:1px solid #eee;border-bottom:1px solid #fff;padding-top:3px;color:#333;background:#fff;font-weight:bold;outline:none;}.stream-subtabs .stream-tab.active .tab-text{color:#333;margin-top:-1px;font-weight:bold;outline:none;}.stream-subtabs .stream-tab-separator{line-height:25px;color:#999;}.profile-header .stream-tabs .stream-tab.active .tab-text,.profile-header .stream-tabs .stream-tab.active .tab-text:hover{border-color:#eee;border-bottom-color:#fff;color:#333;background:#fff;}.stream-tabs .saved-search-icon{background-image:url(http://a1.twimg.com/a/1312996508/phoenix/img/sprite-icons.png);background-position:-224px -80px;width:12px;height:12px;margin-right:0;}.stream-tabs a:hover .saved-search-icon{background-position:-240px -80px;}.stream-tabs .list-icon{width:12px;height:12px;background-image:url(http://a1.twimg.com/a/1312996508/phoenix/img/sprite-icons.png);background-position:-64px -64px;margin-right:1px;}.stream-tabs a:hover .list-icon{background-position:-64px -96px;}.stream-tabs .delete-icon{position:absolute;right:-2px;top:0;}.stream-tabs .lock-icon{position:absolute;right:10px;top:8px;}ul.stream-tabs li ul.drop-down{-webkit-border-radius:4px;-webkit-border-top-left-radius:0;-moz-border-radius:4px;-moz-border-radius-topleft:0;border-radius:4px;border-top-left-radius:0;}ul.stream-tabs li{position:relative;}ul.stream-tabs .tab-text:hover{background:#eee;border-color:#eee;}ul.stream-tabs li.dropdown-link .tab-text:hover{padding-bottom:2px;}ul.stream-tabs li.open,ul.stream-tabs li.open:hover,ul.stream-tabs li.open .tab-text,ul.stream-tabs li.open .tab-text:hover{background:#999;border-color:#999;color:#fff;text-shadow:none;}.route-search ul.stream-tabs li.open,.route-search ul.stream-tabs li.open,.route-home .stream-title ul.stream-tabs li.open,.route-home .stream-title ul.stream-tabs li.open{margin-top:3px;}.route-search ul.stream-tabs li.open .tab-text,.route-search ul.stream-tabs li.open .tab-text:hover,.route-home .stream-title ul.stream-tabs li.open .tab-text,.route-home .stream-title ul.stream-tabs li.open .tab-text:hover{padding:0 6px;z-index:auto!important;}.promoted-tweet{cursor:default;}.promoted-tweet .tweet-labels{width:100%;height:1%;}.stream-item:hover .promoted-tweet .tweet-labels .tweet-label{color:#333!important;}.promoted-tweet:hover{background-color:#ffce6!important;border-color:#e7e3ce!important;}.promoted-tweet .dismiss-action,.stream-item-feedback .cancel-feedback,.stream-item-feedback .close-feedback{font-size:11px;cursor:pointer;}.promoted-tweet .dismiss-action{padding-left:5px;display:none;}.stream-item-feedback{background:#f5f5f5;padding:15px 20px;cursor:default;}.stream-item-feedback p{margin-bottom:5px;}.stream-item-feedback .cancel-feedback{float:right;}.stream-item-feedback .feedback-confirmation{padding-left:58px;background:url(http://a1.twimg.com/a/1312996508/phoenix/img/circle-check.png) no-repeat 0 0;}.promoted-tweet .dismiss-action i,.stream-item-feedback .cancel-feedback i,.stream-item-feedback .close-feedback i{background:url(http://a1.twimg.com/a/1312996508/phoenix/img/sprite-icons.png) no-repeat -270px -14px;display:inline-block;width:12px;height:13px;margin-right:2px;opacity:.5;-moz-opacity:.5;filter:alpha(opacity=50);vertical-align:text-bottom;}.promoted-tweet .dismiss-action:hover i,.stream-item-feedback .cancel-feedback:hover i,.stream-item-feedback .close-feedback:hover i{opacity:1;-moz-opacity:1;filter:alpha(opacity=100);}.stream-item:hover .dismiss-action,.related-tweets .stream-item:hover .dismiss-action,.hovered-stream-item .dismiss-action,.stream-item.focused-stream-item .dismiss-action{display:inline;}.stream-item .close-feedback{float:right;}body{font:13px/1.5 Helvetica Neue,Arial,Helvetica,'Liberation Sans',FreeSans,sans-serif;}body.tr{font-family:Arial,Helvetica,'Liberation Sans',FreeSans,sans-serif;}a{color:#2D76B9;text-decoration:none;}a:hover{text-decoration:underline;}a:focus{outline:1px dotted;}hr{border:0;border-top:1px solid rgba(0,0,0,0.1);border-bottom:1px solid rgba(255,255,255,0.3);*border-top:1px solid #000;*border-bottom:1px solid #fff;*filter:alpha(opacity = 30);clear:both;height:0;display:block;margin:15px 0 15px 0;}h1{font-size:25px;}h2{font-size:23px;}h3{font-size:21px;}h4{font-size:19px;}h5{font-size:17px;}h6{font-size:15px;}ol{list-style:decimal;}ul{list-style:disc;}li{margin-left:30px;}b,strong{font-weight:bold;}*{margin:0;padding:0;}fieldset,img{border:0;}body{position:relative;}#doc{width:100%;position:relative;text-align:center;z-index:1;}#top-stuff{position:fixed;_position:relative;top:0;left:0;z-index:12;width:100%;}#flash-object-container{position:absolute;top:-9000px;left:-9000px;}#page-outer{width:1000px;padding-top:60px;margin:0 auto 0 auto;_padding-top:20px;}#front-container,#page-container{width:920px;margin:0 40px;position:relative;z-index:1;-webkit-border-radius:5px;-moz-border-radius:5px;border-radius:5px;overflow:hidden;text-align:left;}.main-content,.details-pane{color:#444;}.main-content{width:540px;float:left;display:inline-block;z-index:4;-webkit-border-radius:5px;-moz-border-radius:5px;border-radius:5px;box-shadow:0 3px 4px rgba(0,0,0,.5);-moz-box-shadow:0 3px 4px rgba(0,0,0,.5);-webkit-box-shadow:0 3px 4px rgba(0,0,0,.5);*border-right:1px solid #eee;position:relative;background:#fff;height:100%;min-height:700px;}.dashboard{_width:325px;max-width:460px;min-width:340px;position:relative;padding:12px 20px;*padding-right:19px;overflow:hidden;-webkit-border-top-right-radius:5px;-moz-border-radius-topright:5px;border-top-right-radius:5px;}#details-pane-outer{position:fixed;z-index:3;left:0;right:0;top:60px;width:100%;_position:static;_width:520px;_float:left;_display:inline-block;}#details-pane-outer.tracking-vertically{position:absolute;}.details-pane-shell{position:relative;width:920px;margin:0 auto;padding:0 40px;_position:static;_width:520px;_padding:0;_margin:0;}#details-pane-outer.tracking-vertically .details-pane-shell{padding:0;}.details-pane{background:#fff;position:relative;left:10px;top:0;max-width:490px;min-width:370px;-webkit-border-top-right-radius:6px;-webkit-border-bottom-right-radius:6px;-moz-border-radius-topright:6px;-moz-border-radius-bottomright:6px;border-top-right-radius:6px;border-bottom-right-radius:6px;box-shadow:0 2px 2px rgba(0,0,0,0.3);-webkit-box-shadow:0 2px 2px rgba(0,0,0,0.3);-moz-box-shadow:0 2px 2px rgba(0,0,0,0.3);display:none;overflow:hidden;_position:static;_width:520px;}#layout-detail{width:4px;height:32px;background:#F4F4F4;*background:transparent;position:fixed;margin:0 0 0 536px;z-index:-1;display:none;}.messages-container .details-pane{min-width:520px;max-width:630px;left:400px;display:block;}#message-drawer{position:absolute;z-index:2;top:41px;width:100%;text-align:center;_left:0;}#message-drawer .message{-webkit-border-bottom-right-radius:5px;-webkit-border-bottom-left-radius:5px;-moz-border-radius-bottomright:5px;-moz-border-radius-bottomleft:5px;background-color:transparent;font-weight:bold;_width:400px;min-width:100px;max-width:490px;width:auto;display:inline-block;font-weight:normal;margin:0 auto;margin-top:-1px;padding:0 6px 5px 6px;border:0;-moz-box-shadow:0 1px 3px rgba(0,0,0,0.2);-webkit-box-shadow:0 1px 3px rgba(0,0,0,0.2);background:#999;background:rgba(0,0,0,0.5);}@media screen and(-webkit-min-device-pixel-ratio:0){#message-drawer .message{padding:0 6px 4px 6px;}}#message-drawer .message .message-inside{background:#fff;padding:8px 12px 8px 16px;display:inline-block;font-size:13px;-webkit-border-bottom-right-radius:3px;-webkit-border-bottom-left-radius:3px;-moz-border-radius-bottomright:3px;-moz-border-radius-bottomleft:3px;min-width:100px;}#message-drawer .message .message-inside span{display:inline-block;color:#333;max-width:440px;vertical-align:middle;}#message-drawer a.dismiss{display:inline-block;padding:6px 6px 2px 6px;background:#fff;height:22px;margin:-5px -10px -10px 10px;font-family:Tahoma;font-weight:bold;font-size:12px;background:#f8f8f8;color:#999;}#message-drawer a.dismiss:hover{text-decoration:none;background:#eee;color:#333;}#message-drawer em.blink{text-decoration:blink;}#first-container .header{background-color:#ededed;background-color:rgba(237,237,237);height:24px;padding:13px;border-bottom:1px solid rgba(0,0,0,.05);}.base-list,.base-list li,.inline-list,.inline-list li{margin:0;padding:0;list-style:none;}.inline-list li{display:inline;}.clearfix:after{content:'. ';display:block;clear:both;visibility:hidden;line-height:0;height:0;}.clearfix{display:inline-block;}html[xmlns] .clearfix{display:block;}* html .clearfix{height:1%;}#doc ::-webkit-scrollbar{width:9px;height:9px;}#doc ::-webkit-scrollbar-button:start:decrement,#doc ::-webkit-scrollbar-button:end:increment{display:block;height:0;background-color:transparent;}#doc ::-webkit-scrollbar-track-piece{background-color:#FAFAFA;-webkit-border-radius:0;-webkit-border-bottom-right-radius:8px;-webkit-border-bottom-left-radius:8px;}#doc ::-webkit-scrollbar-thumb:vertical{height:50px;background-color:#999;-webkit-border-radius:8px;}#doc ::-webkit-scrollbar-thumb:horizontal{width:50px;background-color:#999;-webkit-border-radius:8px;}#off-screen-preload{position:absolute;top:-5000px;left:-5000px;height:1px;width:1px;overflow:hidden;}#off-screen-preload .content-fe-sprites{position:absolute;height:1px;width:1px;background:url(http://a1.twimg.com/a/1312996508/phoenix/img/sprite_icons-contentfe.png);}body.user-style-twttr{background:url(http://a1.twimg.com/a/1312996508/phoenix/img/bg-clouds.png) repeat-x scroll left 40px #C0DEED;color:#333;}body.user-style-twttr a,body.user-style-twttr ul.stream-tabs li,body.user-style-twttr .component .promo strong,body.user-style-twttr .message-thread-preview:hover .message-count{color:#0084B4;}body.user-style-twttr .stream-item:hover .tweet-screen-name,body.user-style-twttr .stream-item:hover .tweet-timestamp,body.user-style-twttr .stream-item:hover .tweet-geo-text,body.user-style-twttr .stream-item:hover .user-profile-link,body.user-style-twttr span.user-stat-link{color:#0084B4!important;}body.user-style-twttr .stream-item:hover,body.user-style-twttr #new-tweets-bar,body.user-style-twttr #new-tweets-bar:active{background-color:rgba(0,132,180,0.1);border-color:rgba(0,132,180,0.15);}body.user-style-twttr .stream-item.feedback-shown:hover{background-color:#fff!important;}body.user-style-twttr #new-tweets-bar:hover{background-color:rgba(0,132,180,0.2);border-color:rgba(0,132,180,0.25);}body.user-style-twttr .user-small-list-item .user-screen-name,body.user-style-twttr .profile-screenname,body.user-style-twttr .title-link,body.user-style-twttr div.latest-tweet .latest-tweet-timestamp,body.user-style-twttr div.embedded-tweet .latest-tweet-timestamp,body.user-style-twttr div.truncated-tweet .latest-tweet-timestamp,body.user-style-twttr .welcome-steps li .active a strong{color:#333;}body.user-style-twttr .dashboard .dot,body.user-style-twttr .dashboard .copyright{color:#999;}body.user-style-twttr #page-container,body.user-style-twttr .user-sidebar-color{background:#DDEEF6;background:rgba(221,238,246,0.9);_background-color:#DDEEF6;}body.loading-body{background:#F5F6F7;}body.loading-body #page-container{display:none;}body.static-page{background:white;}#top-bar-outer{width:100%;height:40px;display:block;text-align:center;position:relative;}#top-bar-bg{width:100%;height:100%;position:absolute;top:0;left:0;background:#111;background:-webkit-gradient(linear,left top,left bottom,from(#333),to(#111));background:-moz-linear-gradient(top,#333,#111);background:transparent9;filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#333333',endColorstr='#111111');box-shadow:0 1px 2px rgba(0,0,0,0.5);-moz-box-shadow:0 1px 2px rgba(0,0,0,0.5);-webkit-box-shadow:0 1px 2px rgba(0,0,0,0.5);}#top-bar{margin:0 auto;width:1000px;text-align:left;}#top-bar .top-bar-inside{width:920px;margin:0 40px;position:relative;}#top-bar ul{float:left;list-style-type:none;margin:0;}#top-bar ul li{margin:0;padding:0;float:left;}#top-bar ul li a{color:#bababa;padding:10px 10px;display:block;font-weight:normal;}body.ja #top-bar ul li a,body.ru #top-bar ul li a{padding:10px 8px;}@media screen and(-webkit-min-device-pixel-ratio:0){#top-bar ul li a{padding:10px 10px 11px 10px;}}#top-bar ul li a:hover{text-decoration:none;}#logo{float:left;}#logo a{text-indent:-9999px;background:transparent url(http://a1.twimg.com/a/1312996508/phoenix/img/twitter_logo_right.png) no-repeat 20px 9px;display:block;color:#fff;height:40px;width:140px;margin-right:5px;outline:none;}body.jp #logo a,body.ru #logo a{margin-right:0;}#top-bar .active-links{position:absolute;right:8px;top:0;}#top-bar .static-links{float:left;}#global-nav{float:left;margin-left:8px;}#global-nav li a{margin-right:1px;outline:none;}#global-nav li a:hover{color:#fff;}#global-nav li:first-child a{border-left:none;}#global-nav li:last-child a{border-right:none;}#global-nav .active a{color:#fff;background-color:#111;background:rgba(0,0,0,0.7);font-weight:bold;}#global-nav .new a{background-image:url(http://a1.twimg.com/a/1312996508/phoenix/img/light.png);background-repeat:no-repeat;background-position:center bottom;}#session{display:inline-block;padding:10px 12px;height:20px;vertical-align:top;cursor:pointer;white-space:nowrap;_width:0;}#new-tweet{display:inline-block;width:16px;height:14px;padding:13px 6px;vertical-align:top;cursor:pointer;}#new-tweet:hover{text-decoration:none;}#new-tweet span{display:block;width:14px;height:14px;vertical-align:top;text-indent:-9999px;background-image:url(http://a1.twimg.com/a/1312996508/phoenix/img/sprite-icons.png);background-position:-176px -96px;font-size:0;}#new-tweet:hover span{background-position:-192px -96px;}#top-bar .vr{border-left:1px solid #040404;border-right:1px solid #2F2F2F;height:26px;display:inline-block;margin:6px 3px 1px 3px;}#session a.profile-links:hover,#session a:hover{text-decoration:none!important;}#session img{display:inline-block;width:20px;height:20px;vertical-align:top;margin-right:6px;border:none;cursor:pointer;}#session .promotional{color:black;padding:3px 6px 3px 5px;font-size:12px;-moz-border-radius:3px;-webkit-border-radius:3px;-moz-box-shadow:0 1px 0 #000;-webkit-box-shadow:0 1px 0 #000;border:0;margin-top:-2px;outline:none;}#search-form{float:left;margin:6px 0 0 0;*margin:5px 0 0 0;opacity:1;position:relative;}#search-form #search-query{border:1px solid black;-moz-border-radius:4px;-webkit-border-radius:4px;font:13px Arial,sans-serif;width:180px;padding:6px 25px 4px 6px;color:#ccc;background:#666;-webkit-box-shadow:0 1px 0 #444;-moz-box-shadow:0 1px 0 #444;box-shadow:0 1px 0 #444;}#search-form #search-query:hover{background:#777;color:#fff;}#search-form span.glass{display:block;position:absolute;cursor:pointer;display:block;right:0;padding:7px 8px 5px 8px;}#search-form span.glass i{background-image:url(http://a1.twimg.com/a/1312996508/phoenix/img/sprite-icons.png);background-position:-224px -96px;width:14px;height:14px;display:block;font-size:0;}#search-form #search-query:focus,#search-form #search-query.focused{outline:none;background:#eee;color:#333;text-shadow:0 1px 0 #fff;border:1px solid #eee;-webkit-box-shadow:0 0 3px #000;-moz-box-shadow:0 0 3px #000;box-shadow:0 0 3px #000;}#top-bar .dropdown{clear:both;position:absolute;right:0;z-index:0;top:-999px;-webkit-border-bottom-right-radius:5px;-webkit-border-bottom-left-radius:5px;-moz-border-radius-bottomright:5px;-moz-border-radius-bottomleft:5px;border-bottom-right-radius:5px;border-bottom-left-radius:5px;background:#121212;-webkit-box-shadow:0 1px 2px rgba(0,0,0,0.6);-moz-box-shadow:0 1px 2px rgba(0,0,0,0.6);box-shadow:0 1px 2px rgba(0,0,0,0.6);zoom:1;min-width:160px;max-height:350px;}#top-bar .active .dropdown{top:40px;}#top-bar ul.user-dropdown{font-size:12px;width:100%;}#top-bar ul.user-dropdown li{clear:both;display:block;width:100%;background:#333;background:rgba(255,255,255,0.1);}#top-bar ul.user-dropdown li:last-child,#top-bar ul.user-dropdown li:last-child a{-webkit-border-bottom-right-radius:5px;-webkit-border-bottom-left-radius:5px;-moz-border-radius-bottomright:5px;-moz-border-radius-bottomleft:5px;border-bottom-right-radius:5px;border-bottom-left-radius:5px;}#top-bar ul.user-dropdown li a,#top-bar ul.user-dropdown li h2{clear:both;display:block;background-image:none;padding:6px 15px;}#top-bar ul.user-dropdown li span{clear:both;display:block;background-image:none;background:#222;padding:6px 15px;-moz-box-shadow:0 -1px #333;border-top:1px solid #000;cursor:default;color:#666!important;}#top-bar ul.user-dropdown li:last-child h2{display:none;}#top-bar ul.user-dropdown li a:hover{background:#666;background:rgba(255,255,255,0.1);color:#fff;}#top-bar #session.active,#top-bar #session:hover{color:#fff;background:#666;background:rgba(255,255,255,0.1);}#top-bar #session.active span{color:#fff;}#session *{outline:none;}#session #screen-name{color:#bababa;cursor:pointer;font-weight:normal;display:inline-block;max-width:200px;overflow:hidden;white-space:nowrap;text-overflow:ellipsis;}body.ru #session #screen-name{max-width:100px;}body.ja #session #screen-name{max-width:100px;}#session #screen-name-dropdown{width:7px;height:7px;display:inline-block;background:transparent url(http://a1.twimg.com/a/1312996508/phoenix/img/sprite-icons.png) no-repeat scroll -79px -68px;vertical-align:top;margin-top:8px;margin-left:1px;}#session:hover #screen-name,#session:hover #signup-link,#session:hover #signin-link,.active #signin-link{color:#fff;}a#signup-link,a#signin-link{color:#BABABA;position:relative;}a#signup-link em,a#signin-link em{font-style:normal;font-size:10px;margin-right:4px;}a#signup-link strong{color:#fc0;}a#signin-link strong{color:#fff;}a#signin-link i{width:13px;height:13px;display:inline-block;vertical-align:middle;background:transparent url(http://a1.twimg.com/a/1312996508/phoenix/img/toggle_down_light.png) no-repeat;position:relative;left:4px;top:-1px;}.active a#signin-link i{background-image:url(http://a1.twimg.com/a/1312996508/phoenix/img/toggle_up_light.png);}#signin-dropdown form{padding:10px;background:#333;background:rgba(255,255,255,0.1);cursor:auto;_width:215px;}#signin-dropdown .textbox span{color:#BABABA!important;}#signin-dropdown .textbox input{width:200px;}#signin-dropdown .subchck{*width:212px;}#signin-dropdown p a{color:#0084B4;}body.ja #signin-dropdown a.mobile{display:none;}#top-bar form.turn-phx-off-form button.turn-phx-off-button{background:none;border:0;color:#BABABA;font-family:'Helvetica Neue',Arial,Helvetica,'Liberation Sans',FreeSans,sans-serif;font-size:12px;padding:6px 15px;text-align:left;}#top-bar form.turn-phx-off-form button::-moz-focus-inner{padding:0;}#top-bar form.turn-phx-off-form:hover{background:#666;background:rgba(255,255,255,0.1);}#top-bar form.turn-phx-off-form:hover,#top-bar form.turn-phx-off-form button:hover{cursor:pointer;color:#fff;}.text-area{position:relative;margin-bottom:10px;}.tweet-thumbnail-container{position:relative;}.tweet-box .twitter-anywhere-tweet-box-editor,.proxy-editor{border:1px solid #ccc;border-radius:4px;-moz-border-radius:4px;-webkit-border-radius:4px;padding:8px;-webkit-box-shadow:0 1px #fff;-moz-box-shadow:0 1px #fff;box-shadow:0 1px #fff;width:482px;height:56px;color:#222;font:14px/18px 'Helvetica Neue',Arial,sans-serif;outline:none;_width:442px;overflow-x:hidden;overflow-y:auto;white-space:pre-wrap;word-wrap:break-word;}.rich-editor .twitter-anywhere-tweet-box-editor{margin-bottom:-5px;color:#555;overflow-y:hidden;position:relative;opacity:.5;filter:alpha(opacity=50);resize:none;}.rich-editor .twitter-anywhere-tweet-box-editor,.proxy-editor{min-height:3em;background-color:#fff;}.rich-editor{background-color:#fff;}.proxy-editor{width:0;opacity:1;filter:alpha(opacity=99);overflow-y:hidden;margin-bottom:-5px;position:absolute;top:0;left:0;border-color:transparent;}.mozilla .proxy-editor{left:1px;}.tweetbox-counter-tipsy{color:#666;text-align:right;display:inline-block;font-size:12px;margin-right:2px;}.mozilla .tweetbox-counter-tipsy,.msie .tweetbox-counter-tipsy{position:relative;top:-8px;}.tweetbox-tipsy .tipsy-inner{max-width:250px!important;}span.tweetbox-tipsy-text{font-size:12px;}.tweetbox-tipsy .tipsy-inner{max-width:250px!important;}span.tweetbox-tipsy-text{font-size:12px;}.tweet-box .tweet-meta{opacity:.6;position:absolute;right:2px;top:5px;}.tweet-box textarea{resize:vertical;}.tweet-box textarea:focus,.tweet-box input[type=text]{-moz-box-shadow:0 0 8px rgba(82,168,236,0.5);-webkit-box-shadow:0 0 8px rgba(82,168,236,0.5);border-color:rgba(82,168,236,0.75)!important;}.condensed .twitter-anywhere-tweet-box-editor,.condensed .proxy-editor{height:15px!important;min-height:15px!important;overflow:hidden;}.tweet-box-title{overflow:hidden;padding:1px 0;}body.tr .tweet-box h2{font:bold 18px Arial,sans-serif;}.tweet-box h2{font:bold 18px Helvetica Neue,Helvetica,sans-serif;text-shadow:0 1px 0 #fff;margin:0 0 6px 0;color:#999;}body .latest-status-text{font:13px/2 'helvetica neue',helvetica,arial,sans-serif;color:#999;float:right;}body .latest-status-text a{color:#999!important;}.twttr-dialog-content .tweet-box h2{display:none;}.tweet-box textarea:hover{outline:none;border:1px solid #999;cursor:text!important;}.condensed .tweet-button-container{display:none;}.tweet-counter{background-color:transparent;color:#999;display:inline-block;width:35px;border:0;font:normal 16px 'helvetica neue','lucida grande',helvetica,arial;padding:0 3px;position:relative;vertical-align:top;top:5px;text-align:right;}.tweet-button-sub-container{display:inline-block;}.tweet-counter-proxy{position:absolute;}.tweet-counter.warn{color:#5c0002;}.tweet-counter.superwarn{color:#d40d12;}.tweet-button-container{position:relative;text-align:right;margin:5px 0 3px 0;height:29px;z-index:3;}.tweet-box .geo-activation-prompt{display:block;text-align:left;}.tweet-spinner{position:relative;vertical-align:top;top:7px;right:4px;}.twttr-editor .twitter-media-thumbs{display:none;}.twttr-editor.has-thumbnails textarea{vertical-align:top;resize:none;}.twttr-editor.has-thumbnails .twitter-media-thumbs{display:block;position:absolute;bottom:1px;left:1px;right:1px;height:60px;background:#f1f1f1;border-radius:0 0 3px 3px;-moz-border-radius:0 0 3px 3px;-webkit-border-radius:0 0 3px 3px;}.twttr-editor.has-thumbnails.closing .twitter-media-thumbs{display:none;}.twttr-editor.has-thumbnails.html4 .twitter-media-thumbs{height:37px;}.twttr-editor.rich-editor .twitter-media-thumbs{bottom:-4px;}.twitter-media-thumbs .media-thumbnails{position:relative;height:48px;max-width:240px;margin:6px 9px;float:left;}.html4 .twitter-media-thumbs .media-thumbnails{height:25px;}.html4.photo-2 .twitter-media-thumbs .media-thumbnails{height:52px;}.html4.photo-3 .twitter-media-thumbs .media-thumbnails{height:79px;}.twitter-media-thumbs .media-thumbnails-message{position:relative;float:left;height:60px;line-height:60px;font-size:13px;color:#a9a9a9;margin-left:8px;}.html4 .twitter-media-thumbs .media-thumbnails-message{height:37px;line-height:37px;}.html4.photo-2 .twitter-media-thumbs .media-thumbnails-message{height:64px;line-height:64px;}.html4.photo-3 .twitter-media-thumbs .media-thumbnails-message{height:91px;line-height:91px;}.page-header{background:#f5f5f5;border-radius:5px 5px 0 0;-moz-border-radius:5px 5px 0 0;-webkit-border-top-left-radius:5px;-webkit-border-top-right-radius:5px;padding:15px 20px 0 20px;position:relative;z-index:2;zoom:1;}.page-header h1{font-size:20px;font-weight:300;color:#333;text-shadow:0 1px 0 #fff;}.page-header .stream-tabs{margin:15px -20px 0 -20px;}.profile-header{background:#fff;border-radius:5px 5px 0 0;-moz-border-radius:5px 5px 0 0;-webkit-border-top-left-radius:5px;-webkit-border-top-right-radius:5px;}.stream-manager{z-index:1;}.user-content-medium{line-height:16px;padding:10px 20px;font-size:14px;line-height:17px;min-height:34px;display:block;}.user-content-medium .user-content-image{display:block;float:left;height:48px;overflow:hidden;width:48px;margin-top:2px;}.user-content-medium .user-content-rest{margin-left:58px;}.user-content-medium .user-content-rest .user-profile-link{color:#333;}.user-content-medium .user-content-rest .full-name{color:#999;font-size:12px;}.user-content-medium .user-content-rest .user-profile-link:hover{text-decoration:underline;}.user-content-medium .user-content-rest .user-description{color:#666;padding:1px 0;font:italic 13px/18px Georgia,Palatino,serif;word-wrap:break-word;}.user-content-medium .user-content-rest .user-description a,.user-content-medium .user-content-rest .user-meta a{color:#666;overflow:hidden;}.user-content-medium .user-content-rest .user-meta{color:#999;font-size:11px;line-height:14px;word-wrap:break-word;}.user-content-medium .user-content-rest .user-meta .followed-by-you{display:none;}.who-to-follow-suggestions-stream .user-content-medium .user-content-rest .user-meta .followed-by-you{display:inline;}.recent-tweets .more-link,.related-tweets .more-link{clear:both;float:left;margin-left:20px;margin-top:10px;}.stream-user-buttons{float:right;position:relative;padding-left:1em;}.stream-user-buttons .button{margin-left:2px;}.stream-user-buttons .unfollow-button em.wrapper{text-shadow:none;font-style:normal;padding:0 5px;}.stream-user-buttons .unfollow-button em b{position:absolute;}.stream-user-buttons .unfollow-button em b.unfollow{position:static;visibility:hidden;}.stream-user-buttons .unfollow-button:hover em b{visibility:hidden;}.stream-user-buttons .unfollow-button:hover em b.unfollow{visibility:visible;}body.ja .stream-item .unfollow-button{height:28px;}body.ja .stream-item .unfollow-button .you-follow{margin-top:1.5em;}.stream-user-buttons .button .down-arrow{margin-left:0;}.stream-user-buttons div.dismiss{text-align:right;margin:1px 2px 0 0;display:none;}.who-to-follow-suggestions-stream .stream-user-buttons div.dismiss,.user-similarities-stream .stream-user-buttons div.dismiss{display:block;}.stream-user-buttons div.dismiss a{color:#AAA;font-size:11px;}.tweet{padding:10px 20px;font-size:15px;position:relative;zoom:1;}.tweet a:hover{text-decoration:underline;}a.twitter-hashtag,a.twitter-atreply,a.pretty-link{white-space:nowrap;}.hash-text{white-space:normal;}.pretty-link a.twitter-hashtag:hover,.pretty-link a.twitter-atreply:hover,a.pretty-link:hover,.screen-name-and-location a.pretty-link:hover{text-decoration:none;}.pretty-link a.twitter-hashtag:hover span.at-text,.pretty-link a.twitter-atreply:hover span.at-text,a.pretty-link:hover span.at-text,.pretty-link a.twitter-hashtag:hover span.hash-text,.pretty-link a.twitter-atreply:hover span.hash-text,a.pretty-link:hover span.hash-text{text-decoration:underline;_background:transparent;}span.hash{display:inline-block;filter:alpha(opacity=70);_filter:none;opacity:.7;}span.at{display:inline-block;filter:alpha(opacity=50);_filter:none;opacity:.5;}span.at:hover,span.hash:hover{cursor:pointer;}.tweet-image{float:left;height:48px;overflow:hidden;width:48px;margin-top:3px;}.tweet-content{margin-left:58px;min-height:48px;}.tweet-row{display:block;position:relative;line-height:15px;}.tweet-corner{display:inline-block;margin-right:10px;}.tweet-full-name{color:#999;font-size:12px;}.tweet-user-follow,.tweet-user-follow a{color:#5EBF7E!important;font-size:12px;}.simple-tweet-content .tweet-full-name{font-size:11px;}.tweet-screen-name{font-weight:bold;color:#333!important;}.tweet-user-block-image{width:32px;height:32px;float:left;}.tweet-user-block-name{margin-left:40px;min-height:36px;line-height:16px;padding-top:0;}.tweet-user-block-screen-name{display:inline-block;color:#333;font-weight:bold;margin-top:-2px;}.tweet-user-block-full-name{display:block;font-size:12px;margin-top:1px;color:#999;}.tweet hr{margin:20px 0;}.tweet .speech-bubble{position:absolute;margin:-22px 0 0 32px;width:11px;height:6px;background:url(http://a1.twimg.com/a/1312996508/phoenix/img/divot-bubble.gif) no-repeat;}.tweet-timestamp,.tweet-contributors{color:#999!important;font-size:11px;}body.new-tweet-labels .tweet-timestamp,body.new-tweet-labels .tweet-source{display:inline-block;line-height:1;position:relative;top:3px;}body.new-tweet-labels.mozilla .tweet-timestamp,body.new-tweet-labels.mozilla .tweet-source{top:1px;}.details-pane-tweet .tweet-timestamp{line-height:1.9;}.tweet-source,.tweet-source a{color:#999;font-size:11px;}.tweet-geo-text{color:#999!important;font-size:11px;}span.inlinemedia-icons{display:inline-block;margin-right:0!important;}a .geo-pin{background:#999 url(http://a1.twimg.com/a/1312996508/phoenix/img/sprite-icons.png) no-repeat -305px -97px;display:inline-block;height:11px;width:7px;}span.geo-pin{background:transparent url(http://a1.twimg.com/a/1312996508/phoenix/img/sprite-icons.png) no-repeat -224px -64px;display:inline-block;height:11px;width:7px;margin-right:3px!important;margin-top:1px!important;}.stream-item.last-new-tweet{border-bottom:1px solid #b3b3b3!important;z-index:1;}.stream-item:hover span.geo-pin{background-color:transparent!important;}.tweet-text{padding:0;font-family:Arial,'Helvetica Neue',sans-serif;line-height:19px;word-wrap:break-word;}.tweet-text-rtl{direction:rtl;unicode-bidi:embed;text-align:right;padding-right:2px;}.tweet-text-rtl a{direction:ltr;unicode-bidi:bidi-override;}.tweet-meta{color:#999;font-size:11px;font-style:normal;}.tweet-meta i.at{color:#999;font-style:normal;font-size:12px;}.favorited-icon{display:inline-block;background:url(http://a1.twimg.com/a/1312996508/phoenix/img/sprite-icons.png) no-repeat scroll 0 0 transparent;background-position:-64px 0;height:15px;margin:0 2px 0;outline:medium none;text-indent:-99999px;width:15px;display:none;}.tweet-meta .reply-icon{margin-right:-3px!important;margin-bottom:-3px!important;text-indent:-9999px;vertical-align:baseline;}.extra-icons{position:absolute;top:0;right:5px;}.retweet-icon{display:inline-block;background:url(http://a1.twimg.com/a/1312996508/phoenix/img/sprite-icons.png) no-repeat scroll -32px -96px transparent;overflow:hidden;width:15px;height:12px;margin-right:-2px!important;margin-bottom:-3px!important;}.tweet-meta em,.tweet-meta i{font-style:normal;}.tweet-meta .photo,.tweet-meta .video,.tweet-meta .song,.tweet-meta .generic{position:relative;top:1px;width:16px;margin-right:3px;margin-bottom:-3px;height:14px;background:url(http://a1.twimg.com/a/1312996508/phoenix/img/sprite-icons.png) no-repeat;display:inline-block;vertical-align:top;}.tweet-meta .photo{background-position:0 -96px;}.tweet-meta .video{background-position:-16px -96px;}.tweet-meta .generic{width:12px;background-position:-48px -96px;}.tweet-meta .song{background-position:-128px -96px;}.tweet-meta .icons *{margin:0 2px;}.stream-tweet .tweet-actions{visibility:hidden;_visibility:visible;}.stream-tweet:hover .tweet-actions,.focused-stream-item .stream-tweet .tweet-actions{visibility:visible;}.stream-tweet:hover .activity-count,.focused-stream-item .stream-tweet .activity-actions{display:inline;}.stream-tweet .activity-count{color:#999;}.tweet-actions{font-size:11px;}.tweet-actions .activity-count{display:none;}.details-pane-tweet .tweet-actions{display:block;margin:3px 0 0 -3px;}body.new-tweet-labels .tweet-actions{position:absolute;right:0;top:4px;}.tweet-actions a{outline:none!important;}.tweet-actions a:hover{text-decoration:none;}.tweet-actions a span b{font-weight:normal;}.tweet-actions a:hover span b{text-decoration:underline;}.tweet-actions a span i{text-indent:-99999px;outline:none;background:transparent url(http://a1.twimg.com/a/1312996508/phoenix/img/sprite-icons.png) no-repeat;width:15px;height:15px;margin:0 2px 0 2px;display:block;}.tweet-actions a span i{display:inline-block;vertical-align:baseline;margin-bottom:-3px;margin-right:3px;position:relative;}.details-pane-tweet .tweet-user-block-screen-name{margin-top:-1px;}.tweet-actions .reply-action span i{background-position:0 0;margin-right:0;margin-left:3px;}.tweet-actions .reply-action:hover span i{background-position:-16px 0;}.tweet-actions .delete-action span i{background-position:-112px 0;}.tweet-actions .delete-action:hover span i{background-position:-128px 0;}.tweet-actions .retweet-action span i{background-position:-176px 0;}.tweet-actions .retweet-action:hover span i{background-position:-192px 0;}.tweet-actions .unretweet-action span i,.tweet-actions .unretweet-action:hover span i{background-position:-240px 0;}.tweet-actions .favorite-action span i{background-position:-32px 0;}.tweet-actions .favorite-action:hover span i{background-position:-48px 0;}.tweet-actions .unfavorite-action span i,.tweet-actions .unfavorite-action:hover span i{background-position:-64px 0;}.tweet-actions .not-relevant-action span i{background-position:-269px -12px;opacity:.5;-moz-opacity:.5;filter:alpha(opacity=50);}.tweet-actions .not-relevant-action:hover span i{opacity:1;-moz-opacity:1;filter:alpha(opacity=100);}.favorite-icon,.retweet-icon{text-indent:-99999px;outline:none;background:transparent url(http://a1.twimg.com/a/1312996508/phoenix/img/sprite-icons.png) no-repeat;width:14px;height:14px;margin:0 2px -1px 2px;display:inline-block;}.favorite-icon{background-position:-48px 0;}.retweet-icon{background-position:-192px 0;width:15px;}.stream-item .stream-tweet .tweet-corner .tweet-meta .retweet-icon{margin-bottom:-2px!important;}.simple-tweet-image{width:40px;}.simple-tweet-content{margin-left:40px;font-size:13px;}.tweet-dogear{background:url(http://a1.twimg.com/a/1312996508/phoenix/img/tweet-dogear.png) no-repeat 24px 25px;position:absolute;top:0;left:0;width:24px;height:25px;}.tweet-favorited .tweet-dogear{background-position:0 0;}.tweet-retweeted .tweet-dogear{background-position:0 -50px;}.tweet-retweeted.tweet-favorited .tweet-dogear{background-position:0 -25px;}.tweet-labels{display:inline-block;}.stream-item:hover .tweet-label,.focused-stream-item .tweet-label{opacity:1;}.tweet-label{background-color:#999;background-image:-webkit-gradient(linear,0 0,0 100%,from(#ccc),to(#aaa));background-image:-moz-linear-gradient(top,#ccc,#aaa);color:#444;margin:0 10px 0 0;padding:1px 5px;text-shadow:0 1px 1px rgba(255,255,255,.5);border-radius:3px;-moz-border-radius:3px;-webkit-border-radius:3px;box-shadow:inset 0 -1px 0 rgba(0,0,0,.25),0 1px 0 rgba(255,255,255,.25);-moz-box-shadow:inset 0 -1px 0 rgba(0,0,0,.25),0 1px 0 rgba(255,255,255,.25);-webkit-box-shadow:inset 0 -1px 0 rgba(0,0,0,.25),0 1px 0 rgba(255,255,255,.25);color:#fff;font-size:11px;line-height:15px;display:inline-block;}.mozilla .tweet-label{padding-bottom:2px;}.tweet .tweet-label{font-size:11px;display:inline-block;margin:4px 0 0 0;}.promoted-label{background:#ffebbe url(http://a1.twimg.com/a/1312996508/phoenix/img/commercial/garuda-overlay.gif) repeat-x 0 0;background-color:#ffebbe;background:-webkit-gradient(linear,0 0,0 100%,from(#fff39b),to(#ffca7d));background:-moz-linear-gradient(top,#fff39b,#ffca7d);color:#333!important;box-shadow:inset 0 -1px 0 #e4b775;-moz-box-shadow:inset 0 -1px 0 #e4b775;-webkit-box-shadow:inset 0 -1px 0 #e4b775;text-decoration:none;}body .dashboard .user-small-list-item:hover div.user-meta a.promoted-label,body .dashboard .user-small-list-item:hover div.user-meta a.promoted-label-new{color:#333!important;}.stream-item:hover .promoted-label,.focused-stream-item .promoted-label{background-color:#ffebbe;background:-webkit-gradient(linear,0 0,0 100%,from(#ffed65),to(#ffad37));background:-moz-linear-gradient(top,#ffed65,#ffad37);box-shadow:inset 0 -1px 0 #d6902b;-moz-box-shadow:inset 0 -1px 0 #d6902b;-webkit-box-shadow:inset 0 -1px 0 #d6902b;color:#333;}.top-tweet-label{background-color:#d7eaf5;background:-webkit-gradient(linear,0 0,0 100%,from(#d7eaf5),to(#b6d8ea));background:-moz-linear-gradient(top,#d7eaf5,#b6d8ea);color:#333;-webkit-box-shadow:inset 0 -1px 0 #99c5e2;-moz-box-shadow:inset 0 -1px 0 #99c5e2;box-shadow:inset 0 -1px 0 #99c5e2;}.icon-link{font-size:11px;color:#999;}.icon-link i{display:inline-block;margin-right:4px;}.icon-link b{font-weight:normal;color:inherit;}a.icon-link:hover{text-decoration:none;}a.icon-link:hover b{text-decoration:underline;}i.badge-tweet{background:url(http://a1.twimg.com/a/1312996508/phoenix/img/tweet-badges.png) no-repeat 0 0;width:18px;height:14px;position:relative;top:3px;*top:0;}i.badge-tweet-promoted{background-position:0 0;}i.badge-tweet-top{background-position:0 -14px;}.user-name-info .user-meta .icon-link{position:relative;top:-2px;}.stream-item a.tweet-context{color:#999;}ul.trends li a span.tweet-context{padding-left:10px;}ul.trends li.promoted-trend a,ul.trends li.promoted-trend a:hover{text-decoration:none;}ul.trends li.promoted-trend a:hover span.trend-term,ul.trends li.promoted-trend a:hover span.tweet-context b{text-decoration:underline;}ul.trends li.promoted-trend a.trend-link:hover,ul.trends li.promoted-trend a.tweet-label:hover{text-decoration:underline;}ul.trends li.promoted-trend a.trend-link-arrow:hover{text-decoration:none;}.tipsy{padding:5px;font-size:10px;position:absolute;z-index:100000;opacity:.8;filter:alpha(opacity=80);}.tipsy-inner{padding:5px 8px 4px 8px;background-color:black;color:white;max-width:200px;text-align:center;}.tipsy-inner{border-radius:3px;-moz-border-radius:3px;-webkit-border-radius:3px;}.tipsy-arrow{position:absolute;background:url(http://a1.twimg.com/a/1312996508/phoenix/img/tipsy.gif) no-repeat top left;width:9px;height:5px;}.tipsy-n .tipsy-arrow{top:0;left:50%;margin-left:-4px;}.tipsy-nw .tipsy-arrow{top:0;left:10px;}.tipsy-ne .tipsy-arrow{top:0;right:10px;}.tipsy-s .tipsy-arrow{bottom:0;left:50%;margin-left:-4px;background-position:bottom left;}.tipsy-sw .tipsy-arrow{bottom:0;left:10px;background-position:bottom left;}.tipsy-se .tipsy-arrow{bottom:0;right:10px;background-position:bottom left;}.tipsy-e .tipsy-arrow{top:50%;margin-top:-4px;right:0;width:5px;height:9px;background-position:top right;}.tipsy-w .tipsy-arrow{top:50%;margin-top:-4px;left:0;width:5px;height:9px;}</style>";
                strHtml += "</head>";
                strHtml += "<body>";
                strHtml += "<img src='" + IconURL + "' align='left'>";
                strHtml += "<table>";
                strHtml += "<tr>";
                strHtml += "<td width='480'>";
                strHtml += "<small><strong>" + NameEN + "</strong> " + NameJP + "</small><br>";
                strHtml += ReplaceLink(Comment) + "<br>";
                strHtml += "<small>" + strTime + "</small>";
                //            strHtml += "<small>" + strTime + " お気に入り リツイート 返信</small>";
                strHtml += "</td>";
                strHtml += "</tr>";
                strHtml += "</table>";
                strHtml += "</body>";
                strHtml += "</html>";

            }
            string layoutFile = Path.Combine(Path.GetFullPath(Path.GetDirectoryName(Application.ExecutablePath)), "layout.html");
            System.IO.File.WriteAllText(layoutFile, strHtml, System.Text.Encoding.GetEncoding("shift_jis"));
            webBrowser1.Navigate(layoutFile);
        }
        //--------------------------------------------------------------------------
        //ListView選択変更
        //--------------------------------------------------------------------------
        private void listViewFont(bool bChangeUser)
        {
            //フォントを強調
            int iBold = 0;
            TwitterUserData tlv = TwitterListViewDictionary[treeView1.SelectedNode.Tag.ToString()];
            foreach (ListViewItem lvi in listView1.Items)
            {
                if (g_bUpDown == false)
                {
                    if (lvi.Index >= tlv.SelectIndex)
                    {
                        lvi.Font = new Font(this.Font, FontStyle.Regular);
                    }
                    else
                    {
                        lvi.Font = new Font(this.Font, FontStyle.Bold);
                        iBold++;
                    }
                }
                else
                {
                    if (lvi.Index <= tlv.SelectIndex)
                    {
                        lvi.Font = new Font(this.Font, FontStyle.Regular);
                    }
                    else
                    {
                        lvi.Font = new Font(this.Font, FontStyle.Bold);
                        iBold++;
                    }
                }
            }
            //合計数
            tlv.NotReadNum = iBold;
            if (tlv.NotReadNum == 0)
            {
                tlv.node.NodeFont = new Font(this.Font, FontStyle.Regular);
            }
            else
            {
                tlv.node.NodeFont = new Font(this.Font, FontStyle.Bold);
            }
            if(tlv.TweetType != TwitterUserData.TWEET_TYPE_NULL)
            {
                tlv.node.Text = tlv.CallScreenName + "(" + tlv.NotReadNum + ")";
            }
            //最初以外の長さを調整
            listView1.Columns[1].Width = -2;
            listView1.Columns[2].Width = -2;
            //スクロール
            if (bChangeUser == true)
            {
                if (tlv.SelectIndex <= listView1.Items.Count - 1)
                {
                    listView1.Items[tlv.SelectIndex].EnsureVisible();
                    listView1.Items[tlv.SelectIndex].Selected = true;
                }
            }
        }
        //--------------------------------------------------------------------------
        //--------------------------------------------------------------------------
        public Bitmap GetProfileImage(string url)
        {
            try
            {
                // サイズ指定テキストの定義
                WebRequest image_req = WebRequest.Create(url);
                // 画像を取得
                WebResponse image_res = image_req.GetResponse();
                // BITMAPに変換
                Stream stream = image_res.GetResponseStream();
                Bitmap bitmap = new Bitmap(stream);
                stream.Close();
                image_res.Close();
                return bitmap;
            }
            catch
            {
                return null;
            }
        }
        //--------------------------------------------------------------------------
        //ユーザーを変更処理
        //--------------------------------------------------------------------------
        private void ChangeUserName()
        {
            if (backgroundWorker1.IsBusy)
            {
                TwitterUserData ttlv = g_TwitterThreadListView[g_iTwitterThredListIndex].g_tlv;
                if (treeView1.SelectedNode.Tag.ToString() == ttlv.UserName + ttlv.CallName)
                {
                    treeView1.SelectedNode = g_selectBeforeNode; 
                    MessageBox.Show("取得中のユーザーは選択出来ません");
                    return;
                }
            }
            if (treeView1.SelectedNode.Text == "") return;
            if (treeView1.SelectedNode.Tag == null) return;
            listView1.BeginUpdate();
            listView1.Items.Clear();
            TwitterUserData tlv = TwitterListViewDictionary[treeView1.SelectedNode.Tag.ToString()];
            //既読分は削除
            if (g_bUpDown == false)
            {
                for (int i = tlv.tlvi.Count - 1; i >= 0; i--)
                {
                    TwitterTweetData tlvi = tlv.tlvi[i];
                    if (tlv.SelectIndex < i)
                    {
                        tlv.tlvi.Remove(tlvi);
                    }
                }
                if (tlv.tlvi.Count > 0)
                {
                    tlv.SelectIndex = tlv.tlvi.Count - 1;
                }
            }
            else
            {
                int count = tlv.tlvi.Count;
                for (int i = 0; i < count; i++)
                {
                    TwitterTweetData tlvi = tlv.tlvi[count - 1 - i];
                    if (tlv.SelectIndex > i)
                    {
                        tlv.tlvi.Remove(tlvi);
                    }
                }
                tlv.SelectIndex = 0;
            }
            homeImageList.Images.Clear();
            List<Image> imageList = new List<Image>();
            //それから書き直し
            foreach (TwitterTweetData tlvi in tlv.tlvi)
            {
                ListViewItem lvi;

                //string strItem = tlvi.Tweet;
                string strItem = tlvi.UserName + " " + tlvi.ScreenName + tlvi.ReTweet + "\n" + tlvi.Tweet;
                if (g_bUpDown == false)
                {
                    lvi = listView1.Items.Add(strItem);
                }
                else
                {
                    lvi = listView1.Items.Insert(0, strItem);
                }
                lvi.BackColor = (tlvi.Favorited == true) ? Color.Yellow : Color.White;
                lvi.ForeColor = (tlvi.ReTweeted == true) ? Color.Green : Color.Black;

                if (tlvi.Icon != null)
                {
                    imageList.Add(tlvi.Icon);
                }
                lvi.ImageIndex = imageList.Count - 1;
                AddTweet(lvi, tlvi);
            }
            homeImageList.Images.AddRange(imageList.ToArray());
            listView1.EndUpdate();
            listViewFont(true);
        }
        //--------------------------------------------------------------------------
        //自動更新のチェック
        //--------------------------------------------------------------------------
        private void AutoUpdateCheckBox_CheckedChanged(object sender, EventArgs e)
        {
            if (AutoUpdateCheckBox.Checked == false)
            {
                toolStripStatusLabel1.Text = "";
                timer1.Enabled = false;
                iTimer = 0;
            }
            else
            {
                timer1.Enabled = true;
            }
        }
        //--------------------------------------------------------------------------
        //タイマー
        //--------------------------------------------------------------------------
        int iTimer = 0;
        private void timer1_Tick(object sender, EventArgs e)
        {
            iTimer++;
            toolStripStatusLabel1.Text = "自動更新まで" + (60 - (iTimer % 60)) + "秒";
            if ((iTimer % 60) == 0)
            {
                List<TwitterUserData> ltlv = new List<TwitterUserData>();
                foreach (TwitterUserData tlv in TwitterListViewDictionary.Values)
                {
                    if (tlv.node == treeView1.SelectedNode)
                    {
                        ltlv.Add(tlv);
                    }
                }
                if (ltlv.Count >= 1)
                {
                    treeView1.Enabled = false;
                    StartAllTimeLineThread(ltlv, true, true, 0);
                }
            }
        }
        //--------------------------------------------------------------------------
        //ツイート文字数
        //--------------------------------------------------------------------------
        private void TweetTextBox_TextChanged(object sender, EventArgs e)
        {
            int tweetNumber = 140 - TweetTextBox.Text.Length;
            TweetNumberLabel.Text = tweetNumber.ToString();
            if (tweetNumber >= 20)
            {
                TweetNumberLabel.ForeColor = Color.Gray;
            }
            else if (tweetNumber > 10)
            {
                TweetNumberLabel.ForeColor = Color.Brown;
            }
            else
            {
                TweetNumberLabel.ForeColor = Color.Red;
            }
            if (tweetNumber == 140)
            {
                TweetButton.Text = "ツイート";
            }
        }
        //--------------------------------------------------------------------------
        //ツイートボタン
        //--------------------------------------------------------------------------
        private void TweetButton_Click(object sender, EventArgs e)
        {
            TweetButton.Enabled = false;
            treeView1.Enabled = false;

            List<TwitterUserData> ltlv = new List<TwitterUserData>();
            TwitterUserData tweetTlv = new TwitterUserData();
            tweetTlv.CallName = "update";
            tweetTlv.UserName = TweetTextBox.Text;
            tweetTlv.CallScreenName = g_Twitter.UserName;
            tweetTlv.TweetType = TwitterUserData.TWEET_TYPE_UPDATE;
            ltlv.Add(tweetTlv);
            //書き込み
            string encmes = string.Format("status={0:s}", System.Web.HttpUtility.UrlEncode(TweetTextBox.Text));
            if (TweetButton.Text == "返信")
            {
                encmes += "&in_reply_to_status_id=" + TweetButton.Tag;
            }
            string url = "http://api.twitter.com/1/statuses/update.xml";
            string result = g_oAuthTwitter.oAuthWebRequest(oAuthTwitter.Method.POST, url, encmes);
            //これでは駄目な気もする？
            foreach (TwitterUserData tlv in TwitterListViewDictionary.Values)
            {
                if (tlv.node == treeView1.SelectedNode)
                {
                    ltlv.Add(tlv);
                }
            }
            StartAllTimeLineThread(ltlv, true, true, 0);
            TweetTextBox.Text = "";
            TweetButton.Text = "ツイート";
            


            /*
                        //書き込み
                        string encmes = string.Format("status={0:s}", System.Web.HttpUtility.UrlEncode(TweetTextBox.Text));
                        if (TweetButton.Text == "返答")
                        {
                            encmes += "&in_reply_to_status_id=" + TweetButton.Tag;
                        }
                        string url = "http://api.twitter.com/1/statuses/update.xml";
                        string result = g_oAuthTwitter.oAuthWebRequest(oAuthTwitter.Method.POST, url, encmes);
                        TweetTextBox.Text = "";
                        TweetButton.Text = "ツイート";

                        //書き込みの時ロードするのは自分ぐらい？
                        List<TwitterUserData> ltlv = new List<TwitterUserData>();
                        foreach (TwitterUserData tlv in TwitterListViewDictionary.Values)
                        {
                            if (tlv.node == treeView1.SelectedNode)
                            {
                                ltlv.Add(tlv);
                                treeView1.Enabled = false;
                                StartAllTimeLineThread(ltlv, true, true, 0);
                                goto LOOPEND;
                            }
                        }
                        TweetButton.Enabled = true;
                    LOOPEND:
                        ;
             * 
             * 
             */
        }
        private static string GetDefaultExePath(string keyPath)
        {
            string path = "";

            // レジストリ・キーを開く
            // 「HKEY_CLASSES_ROOT\xxxxx\shell\open\command」
            RegistryKey rKey = Registry.ClassesRoot.OpenSubKey(keyPath);
            if (rKey != null)
            {
                // レジストリの値を取得する
                string command = (string)rKey.GetValue(String.Empty);
                if (command == null)
                {
                    return path;
                }

                // 前後の余白を削る
                command = command.Trim();
                if (command.Length == 0)
                {
                    return path;
                }

                // 「"」で始まる長いパス形式かどうかで処理を分ける
                if (command[0] == '"')
                {
                    // 「"～"」間の文字列を抽出
                    int endIndex = command.IndexOf('"', 1);
                    if (endIndex != -1)
                    {
                        // 抽出開始を「1」ずらす分、長さも「1」引く
                        path = command.Substring(1, endIndex - 1);
                    }
                }
                else
                {
                    // 「（先頭）～（スペース）」間の文字列を抽出
                    int endIndex = command.IndexOf(' ');
                    if (endIndex != -1)
                    {
                        path = command.Substring(0, endIndex);
                    }
                    else
                    {
                        path = command;
                    }
                }
            }

            return path;
        }
        //--------------------------------------------------------------------------
        //ココまで未読にする
        //--------------------------------------------------------------------------
        private void NoReadTweetToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (listView1.SelectedItems.Count < 1) return;
            TwitterUserData tlv = TwitterListViewDictionary[treeView1.SelectedNode.Tag.ToString()];
            tlv.SelectIndex = listView1.SelectedItems[0].Index;

            if (g_bUpDown == false)
            {
                tlv.SelectID = tlv.tlvi[tlv.SelectIndex].TweetId;
            }
            else
            {
                tlv.SelectID = tlv.tlvi[tlv.tlvi.Count - 1 - tlv.SelectIndex].TweetId;
            }
            listViewFont(false);
        }
        //--------------------------------------------------------------------------
        //WEB
        //--------------------------------------------------------------------------
        private void WebToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (listView1.SelectedItems.Count < 1) return;
            TwitterUserData tlv = TwitterListViewDictionary[treeView1.SelectedNode.Tag.ToString()];
            int idx = listView1.SelectedItems[0].Index;
            string url = "https://twitter.com/#!/" + tlv.tlvi[idx].UserName + "/status/" + tlv.tlvi[idx].TweetId;
            Process.Start(GetDefaultExePath(@"http\shell\open\command"), url);
        }
        //--------------------------------------------------------------------------
        //↓下の関数とほぼ同じなので、合併吸収したい
        //--------------------------------------------------------------------------
        private void treeView1_AfterCheck(object sender, TreeViewEventArgs e)
        {
            //選択状態のチェックでなければ特に何もしない。
            if (e.Node != treeView1.SelectedNode) return;

            //タイトルは何も処理しない
            if (treeView1.SelectedNode != null)
            {
                TwitterUserData tlv = TwitterListViewDictionary[treeView1.SelectedNode.Tag.ToString()];
                if (tlv.CallName == "profile" || tlv.CallName == "home")
                {
                    return;
                }
            }
            //アクティブがチェック付きなら
            if (treeView1.SelectedNode.Checked == true)
            {
                //更新
                if (backgroundWorker1.IsBusy == false)
                {
                    TwitterUserData tlv = TwitterListViewDictionary[treeView1.SelectedNode.Tag.ToString()];
                    List<TwitterUserData> ltlv = new List<TwitterUserData>();
                    ltlv.Add(tlv);
                    StartAllTimeLineThread(ltlv, true, true, 0);
                    treeView1.Enabled = false;
                }
            }
            else
            {
                toolStripStatusLabel1.Text = "";
            }
            timer1.Enabled = false;
        }
        //--------------------------------------------------------------------------
        //ListView選択変更
        //--------------------------------------------------------------------------
        private void listView1_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (listView1.SelectedItems.Count < 1) return;
            //選択
            TwitterUserData tlv = TwitterListViewDictionary[treeView1.SelectedNode.Tag.ToString()];
            treeView1.SelectedNode = tlv.node;
            if (tlv.tlvi.Count < 1) return;

            if (g_bUpDown == false)
            {
                tlv.SelectIndex = Math.Min(tlv.SelectIndex, listView1.SelectedItems[0].Index);
                tlv.SelectID = tlv.tlvi[tlv.SelectIndex].TweetId;
            }
            else
            {
                tlv.SelectIndex = Math.Max(tlv.SelectIndex, listView1.SelectedItems[0].Index);
                tlv.SelectID = tlv.tlvi[tlv.tlvi.Count - 1 - tlv.SelectIndex].TweetId;
            }
            //トップの書き込み
            TweetPanel.Visible = false;
            foreach (ListViewItem lvi in listView1.SelectedItems)
            {
                int idx;
                if (g_bUpDown == false)
                {
                    idx = lvi.Index;
                }
                else
                {
                    idx = tlv.tlvi.Count - 1 - lvi.Index;
                }
                SetTopTweet(tlv.tlvi[idx].Tweet, tlv.tlvi[idx].UserName, tlv.tlvi[idx].ScreenName + tlv.tlvi[idx].ReTweet, tlv.tlvi[idx].TweetTime, tlv.tlvi[idx].IconURL);
                lvi.Font = new Font(this.Font, FontStyle.Regular);
                //ボタン表示
                if (tlv.tlvi[idx].UserName == g_Twitter.UserName)
                {
                    TweetButton1.Text = (tlv.tlvi[idx].Favorited) ? "お気に入りから外す" : "お気に入り";
                    TweetButton2.Text = "返信";
                    TweetButton3.Text = "削除";
                }
                else
                {

                    TweetButton1.Text = (tlv.tlvi[idx].Favorited) ? "お気に入りから外す" : "お気に入り";
                    TweetButton2.Text = (tlv.tlvi[idx].ReTweeted) ? "リツイートの取消" : "リツイート";
                    TweetButton3.Text = "返信";
                }
                Tweet1ToolStripMenuItem.Text = TweetButton1.Text;
                Tweet2ToolStripMenuItem.Text = TweetButton2.Text;
                Tweet3ToolStripMenuItem.Text = TweetButton3.Text;
                TweetPanel.Visible = true;
            }
            listViewFont(false);
        }
        //--------------------------------------------------------------------------
        //ツリービューセレクト後
        //--------------------------------------------------------------------------
        TreeNode g_selectBeforeNode;
        private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
        {
            //タイトルは何も処理しない
            AddTweet20ToolStripMenuItem.Visible = true;
            AddTweet200ToolStripMenuItem.Visible = true;
            AddTweet2000ToolStripMenuItem.Visible = true;
            //ListViewContextMenuStrip.Enabled = true;
            DeleteUserToolStripMenuItem.Visible = false;

            if (treeView1.SelectedNode != null)
            {
                TwitterUserData tlv = TwitterListViewDictionary[treeView1.SelectedNode.Tag.ToString()];
                if (tlv.CallName == "profile" || tlv.CallName == "home")
                {
                    //自分以外が削除対象
                    if (tlv.UserName != g_Twitter.UserName && tlv.CallName != "home")
                    {
                        DeleteUserToolStripMenuItem.Visible = true;
                    }
                    //ListViewContextMenuStrip.Enabled = false;
                    //return;
                }
            }
            ChangeUserName();
            //ツリー選択後もリストにフォーカスが欲しい。がこの方法では無理…。
            //listView1.Select();
            //アクティブがチェック付きなら
            if (treeView1.SelectedNode.Checked == true)
            {
                //更新
                if (backgroundWorker1.IsBusy == false)
                {
                    TwitterUserData tlv = TwitterListViewDictionary[treeView1.SelectedNode.Tag.ToString()];
                    List<TwitterUserData> ltlv = new List<TwitterUserData>();
                    ltlv.Add(tlv);
                    StartAllTimeLineThread(ltlv, true, true, 0);
                    treeView1.Enabled = false;
                }
            }
            else
            {
                toolStripStatusLabel1.Text = "";
            }
            timer1.Enabled = false;
        }
        private void treeView1_BeforeSelect(object sender, TreeViewCancelEventArgs e)
        {
             g_selectBeforeNode = treeView1.SelectedNode;
        }
        //--------------------------------------------------------------------------
        //▲▼反転
        //--------------------------------------------------------------------------
        private void button2_Click(object sender, EventArgs e)
        {
            g_bUpDown = !g_bUpDown;
            TweetUpDownButton.Text = (!g_bUpDown) ? "▲" : "▼";
            foreach (TwitterUserData tlv in TwitterListViewDictionary.Values)
            {
                tlv.SelectIndex = (tlv.tlvi.Count > 0) ? (tlv.tlvi.Count - 1) - tlv.SelectIndex : 0;
            }
            ChangeUserName();
        }
        //--------------------------------------------------------------------------
        //削除
        //--------------------------------------------------------------------------
        private void DeleteUserToolStripMenuItem_Click(object sender, EventArgs e)
        {
            foreach (TwitterUserData tlv in TwitterListViewDictionary.Values)
            {
                if (treeView1.SelectedNode != null && tlv.UserName + tlv.CallName == treeView1.SelectedNode.Tag.ToString())
                {
                    //子供から削除
                    foreach (TreeNode node in tlv.node.Nodes)
                    {
                        TwitterListViewDictionary.Remove(node.Tag.ToString());
                    }
                    TwitterListViewDictionary.Remove(tlv.UserName + tlv.CallName);
                    treeView1.SelectedNode.Remove();
                    break;
                }
            }
        }
        //--------------------------------------------------------------------------
        //Webユーザー確認
        //--------------------------------------------------------------------------
        private void WebUserToolStripMenuItem_Click(object sender, EventArgs e)
        {
            TwitterUserData tlv = TwitterListViewDictionary[treeView1.SelectedNode.Tag.ToString()];

            string url = (tlv.UserName == "home") ? "https://twitter.com" : "https://twitter.com/#!/" + tlv.UserName;
            Process.Start(GetDefaultExePath(@"http\shell\open\command"), url);
        }
        //--------------------------------------------------------------------------
        //ユーザー登録
        //--------------------------------------------------------------------------
        private void AddUserTool_Click(int num)
        {
            List<TwitterUserData> ltlv = new List<TwitterUserData>();
            foreach (ListViewItem lvi in listView1.SelectedItems)
            {
                TwitterUserData tlv = TwitterListViewDictionary[treeView1.SelectedNode.Tag.ToString()];
                int idx;
                if (g_bUpDown == false)
                {
                    idx = lvi.Index;
                }
                else
                {
                    idx = tlv.tlvi.Count - 1 - lvi.Index;
                }
                //重複チェック
                foreach (TwitterUserData tud in TwitterListViewDictionary.Values)
                {
                    if (tlv.tlvi[idx].UserName == tud.UserName)
                    {
                        MessageBox.Show(tud.CallScreenName + "は登録済みです");
                        return;
                    }
                }
                TwitterUserData profile = AddTreeViewUser(tlv.tlvi[idx].UserName, "profile", tlv.tlvi[idx].ScreenName, 0, 1, TwitterUserData.TYPE_PROFILE, TwitterUserData.TWEET_TYPE_NULL, true);
                ltlv.Add(profile);
                ltlv.Add(AddTreeViewUser(tlv.tlvi[idx].UserName, "user_timeline", "ツイート", 0, 1, TwitterUserData.TYPE_PROFILE, TwitterUserData.TWEET_TYPE_NORMAL, true));
                ltlv.Add(AddTreeViewUser(tlv.tlvi[idx].UserName, "favorites", "お気に入り", 0, 1, TwitterUserData.TYPE_PROFILE, TwitterUserData.TWEET_TYPE_NORMAL, true));
                //フォローはフォーマットが違う
                //ltlv.Add(AddTreeViewUser(tlv.tlvi[idx].UserName, "friends", "フォローしている", 0, 1, TwitterUserData.TYPE_PROFILE, TwitterUserData.TWEET_TYPE_FOLLOW));
                //ltlv.Add(AddTreeViewUser(tlv.tlvi[idx].UserName, "followers", "フォローされている", 0, 1, TwitterUserData.TYPE_PROFILE, TwitterUserData.TWEET_TYPE_FOLLOW));
                profile.node.ExpandAll();
            }
            treeView1.Enabled = false;
            StartAllTimeLineThread(ltlv, false, true, num);
        }
        private void AddUser32ToolStripMenuItem_Click_1(object sender, EventArgs e)
        {
            AddUserTool_Click(20);
        }
        private void AddUser320ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            AddUserTool_Click(200);
        }
        private void AddUser3200ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            AddUserTool_Click(3200);
        }
        //--------------------------------------------------------------------------
        //再更新
        //--------------------------------------------------------------------------
        private void AddReUpdate(int num)
        {
            SetTopTweet("", "", "", DateTime.Now, "");
            List<TwitterUserData> ltlv = new List<TwitterUserData>();
            foreach (TwitterUserData tlv in TwitterListViewDictionary.Values)
            {
                if (treeView1.SelectedNode != null && tlv.UserName + tlv.CallName == treeView1.SelectedNode.Tag.ToString())
                {
                    if (tlv.CallName == "profile" || tlv.CallName == "home")
                    {
                        //子供から
                        foreach (TreeNode node in tlv.node.Nodes)
                        {
                            TwitterUserData child = TwitterListViewDictionary[node.Tag.ToString()];

                            child.node.Text = child.CallScreenName + "(0)";
                            child.node.NodeFont = new Font(this.Font, FontStyle.Regular);
                            child.tlvi.Clear();
                            child.NewID = 1;
                            child.SelectIndex = 0;
                            child.NotReadNum = 0;
                            ltlv.Add(child);
                        }
                    }
                    else
                    {
                        listView1.Items.Clear();
                        tlv.node.Text = tlv.CallScreenName + "(0)";
                        tlv.node.NodeFont = new Font(this.Font, FontStyle.Regular);
                        tlv.tlvi.Clear();
                        tlv.NewID = 1;
                        tlv.SelectIndex = 0;
                        tlv.NotReadNum = 0;
                        ltlv.Add(tlv);
                    }
                    break;
                }
            }
            if (ltlv.Count > 0)
            {
                //treeView1.Enabled = false;
                StartAllTimeLineThread(ltlv, false, true, num);
            }
        }
        private void AddTweet20ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            AddReUpdate(20);
        }
        private void AddTweet200ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            AddReUpdate(200);
        }
        private void AddTweet2000ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            AddReUpdate(3200);
        }
        //--------------------------------------------------------------------------
        //クライアントサイズ変更
        //--------------------------------------------------------------------------
        private void Form1_ClientSizeChanged(object sender, EventArgs e)
        {
            //バグで最大化したときフォントが一部薄くなる
            if (this.WindowState == System.Windows.Forms.FormWindowState.Maximized)
            {
                listViewFont(false);
            }
        }
        //--------------------------------------------------------------------------
        //ツリーのレイアウトボタン
        //--------------------------------------------------------------------------
        private void TreeLayoutButton_Click(object sender, EventArgs e)
        {
            if(TreeLayoutButton.Text == "←")
            {
                treeView1.Visible = false;
                TreeViewSplitter.Visible = false;
                TreeLayoutButton.Text = "→";
            }
            else
            {
                treeView1.Visible = true;
                TreeViewSplitter.Visible = true;
                TreeLayoutButton.Text = "←";
            }
        }
        private void OptionToolStripMenuItem_Click(object sender, EventArgs e)
        {
            LoginForm();
        }
        //--------------------------------------------------------------------------
        //終了
        //--------------------------------------------------------------------------
        private void ExitToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }
        //--------------------------------------------------------------------------
        //ログイン
        //--------------------------------------------------------------------------
        private void LoginToolStripMenuItem_Click(object sender, EventArgs e)
        {
            LoginForm();
        }

        private void VersionToolStripMenuItem_Click(object sender, EventArgs e)
        {
            AboutBox1 form = new AboutBox1();
            form.ShowDialog();
        }
        //--------------------------------------------------------------------------
        //お気に入り
        //--------------------------------------------------------------------------
        private void TweetButton1_Click(object sender, EventArgs e)
        {
            TweetButton1.Enabled = false;
            //選択
            TwitterUserData tlv = TwitterListViewDictionary[treeView1.SelectedNode.Tag.ToString()];
            foreach (ListViewItem lvi in listView1.SelectedItems)
            {
                int idx;
                if (g_bUpDown == false)
                {
                    idx = lvi.Index;
                }
                else
                {
                    idx = tlv.tlvi.Count - 1 - lvi.Index;
                }
                string url = "http://api.twitter.com/1/favorites/";
                if(tlv.tlvi[idx].Favorited == true)
                {
                    url += "create";
                    tlv.tlvi[idx].Favorited = false;
                    lvi.BackColor =  Color.White;
                }
                else
                {
                    url += "destroy";
                    tlv.tlvi[idx].Favorited = true;
                    lvi.BackColor = Color.Yellow;
                }
                url += "/" + tlv.tlvi[idx].TweetId + ".xml";
                string result = g_oAuthTwitter.oAuthWebRequest(oAuthTwitter.Method.POST, url, "");
            }
            TweetButton1.Enabled = true;
        }
        private void TweetButton2_Click(object sender, EventArgs e)
        {
            TweetButton2.Enabled = false;
            TwitterUserData tlv = TwitterListViewDictionary[treeView1.SelectedNode.Tag.ToString()];
            foreach (ListViewItem lvi in listView1.SelectedItems)
            {

                int idx;
                if (g_bUpDown == false)
                {
                    idx = lvi.Index;
                }
                else
                {
                    idx = tlv.tlvi.Count - 1 - lvi.Index;
                }
                if (TweetButton2.Text == "リツイート")
                {
                    string url = "http://api.twitter.com/1/statuses/retweet/" + tlv.tlvi[idx].TweetId + ".xml";
                    g_oAuthTwitter.oAuthWebRequest(oAuthTwitter.Method.POST, url, "");

                    tlv.tlvi[idx].ReTweeted = true;
                    lvi.ForeColor = Color.Green;

                }
                else if (TweetButton2.Text == "リツイートの取消")
                {
                    string url = "http://api.twitter.com/1/statuses/destroy/" + tlv.tlvi[idx].TweetId + ".xml";
                    g_oAuthTwitter.oAuthWebRequest(oAuthTwitter.Method.POST, url, "");
                    tlv.tlvi.Remove(tlv.tlvi[idx]);
                    lvi.Remove();
                }
                else if (TweetButton2.Text == "返信")
                {
                    TweetTextBox.Text = "@" + tlv.tlvi[idx].UserName + " ";
                    TweetButton.Text = "返信";
                    TweetButton.Tag = tlv.tlvi[idx].TweetId;
                    TweetTextBox.Focus();
                    TweetTextBox.Select(TweetTextBox.Text.Length, 0);
                }
            }
            TweetButton2.Enabled = true;
        }
        private void TweetButton3_Click(object sender, EventArgs e)
        {
            TweetButton3.Enabled = false;
            TwitterUserData tlv = TwitterListViewDictionary[treeView1.SelectedNode.Tag.ToString()];
            foreach (ListViewItem lvi in listView1.SelectedItems)
            {
                int idx;
                if (g_bUpDown == false)
                {
                    idx = lvi.Index;
                }
                else
                {
                    idx = tlv.tlvi.Count - 1 - lvi.Index;
                }
                if (TweetButton3.Text == "削除")
                {
                    string url = "http://api.twitter.com/1/statuses/destroy/" + tlv.tlvi[idx].TweetId + ".xml";
                    g_oAuthTwitter.oAuthWebRequest(oAuthTwitter.Method.POST, url, "");
                    tlv.tlvi.Remove(tlv.tlvi[idx]);
                    lvi.Remove();
                }
                else if (TweetButton3.Text == "返信")
                {
                    TweetTextBox.Text = "@" + tlv.tlvi[idx].UserName + " ";
                    TweetButton.Text = "返信";
                    TweetButton.Tag = tlv.tlvi[idx].TweetId;
                    TweetTextBox.Focus();
                    TweetTextBox.Select(TweetTextBox.Text.Length, 0);
                }
            }
            TweetButton3.Enabled = true;
        }
        //--------------------------------------------------------------------------
        //検索
        //--------------------------------------------------------------------------
        private void SearchTextBox_TextChanged(object sender, EventArgs e)
        {
            SearchButton.Enabled = (SearchTextBox.Text != "") ? true : false; 
        }

        private void SearchButton_Click(object sender, EventArgs e)
        {
/*
            List<TwitterUserData> ltlv = new List<TwitterUserData>();
            foreach (ListViewItem lvi in listView1.SelectedItems)
            {
                TwitterUserData tlv = TwitterListViewDictionary[treeView1.SelectedNode.Tag.ToString()];
                int idx;
                if (g_bUpDown == false)
                {
                    idx = lvi.Index;
                }
                else
                {
                    idx = tlv.tlvi.Count - 1 - lvi.Index;
                }
                //重複チェック
                foreach (TwitterUserData tud in TwitterListViewDictionary.Values)
                {
                    if (tlv.tlvi[idx].UserName == tud.UserName)
                    {
                        MessageBox.Show(tud.ScreenName + "は登録済みです");
                        return;
                    }
                }
                ltlv.Add(AddTreeViewUser(tlv.tlvi[idx].UserName, tlv.tlvi[idx].ScreenName, tlv.tlvi[idx].UserID, 1, TwitterUserData.TYPE_USER));
            }
            StartAllTimeLineThread(ltlv, false, true, num);
*/
        }








    }
}
